Implement actix Responder for Label
This commit is contained in:
parent
d46a165a1a
commit
5a247f823f
|
@ -2,8 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use actix_web::http::header::{ContentDisposition, ContentType, DispositionParam, DispositionType};
|
||||
use actix_web::{error, get, web, HttpResponse, Responder};
|
||||
use actix_web::{error, get, web, Responder};
|
||||
use serde::Deserialize;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
@ -39,15 +38,5 @@ async fn items(
|
|||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
let label = Label::for_items(&items, params.preset.clone().into());
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.insert_header(ContentType(mime::APPLICATION_PDF))
|
||||
.insert_header(ContentDisposition {
|
||||
disposition: DispositionType::Inline,
|
||||
parameters: vec![DispositionParam::Filename(
|
||||
"li7y-item-labels.pdf".to_string(),
|
||||
)],
|
||||
})
|
||||
.body(label.generate().map_err(error::ErrorInternalServerError)?))
|
||||
Ok(Label::for_items(&items, params.preset.clone().into()))
|
||||
}
|
||||
|
|
27
src/label/actix.rs
Normal file
27
src/label/actix.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use actix_web::http::header::{ContentDisposition, ContentType, DispositionParam, DispositionType};
|
||||
use actix_web::{error, HttpResponse, Responder};
|
||||
|
||||
use super::Label;
|
||||
|
||||
impl Responder for Label {
|
||||
type Body = actix_web::body::BoxBody;
|
||||
|
||||
fn respond_to(self, _req: &actix_web::HttpRequest) -> actix_web::HttpResponse<Self::Body> {
|
||||
match self.generate() {
|
||||
Ok(buf) => HttpResponse::Ok()
|
||||
.insert_header(ContentType(mime::APPLICATION_PDF))
|
||||
.insert_header(ContentDisposition {
|
||||
disposition: DispositionType::Inline,
|
||||
parameters: vec![DispositionParam::Filename(
|
||||
"li7y-item-labels.pdf".to_string(),
|
||||
)],
|
||||
})
|
||||
.body(buf),
|
||||
Err(e) => error::ErrorInternalServerError(e).error_response(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
mod actix;
|
||||
mod barcode;
|
||||
mod preset;
|
||||
|
||||
|
|
Loading…
Reference in a new issue