feat(presentation): pipe diary export stream to Body::from_stream
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
Form, Json,
|
Form, Json,
|
||||||
|
body::Body,
|
||||||
extract::{Extension, Path, Query, State},
|
extract::{Extension, Path, Query, State},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Redirect},
|
response::{IntoResponse, Redirect},
|
||||||
@@ -147,14 +148,12 @@ pub async fn export_diary(
|
|||||||
user_id: user.0.value(),
|
user_id: user.0.value(),
|
||||||
format,
|
format,
|
||||||
};
|
};
|
||||||
match export_diary_uc::execute(
|
let stream = export_diary_uc::execute(
|
||||||
&state.app_ctx.repos.diary,
|
&state.app_ctx.repos.diary,
|
||||||
&state.app_ctx.services.diary_exporter,
|
&state.app_ctx.services.diary_exporter,
|
||||||
query,
|
query,
|
||||||
)
|
);
|
||||||
.await
|
(
|
||||||
{
|
|
||||||
Ok(bytes) => (
|
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[
|
[
|
||||||
(axum::http::header::CONTENT_TYPE, content_type.to_string()),
|
(axum::http::header::CONTENT_TYPE, content_type.to_string()),
|
||||||
@@ -163,14 +162,9 @@ pub async fn export_diary(
|
|||||||
format!("attachment; filename=\"{}\"", filename),
|
format!("attachment; filename=\"{}\"", filename),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
bytes,
|
Body::from_stream(stream),
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response()
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("export error: {:?}", e);
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
@@ -314,14 +308,12 @@ pub async fn get_export_html(
|
|||||||
user_id: user_id.value(),
|
user_id: user_id.value(),
|
||||||
format,
|
format,
|
||||||
};
|
};
|
||||||
match export_diary_uc::execute(
|
let stream = export_diary_uc::execute(
|
||||||
&state.app_ctx.repos.diary,
|
&state.app_ctx.repos.diary,
|
||||||
&state.app_ctx.services.diary_exporter,
|
&state.app_ctx.services.diary_exporter,
|
||||||
query,
|
query,
|
||||||
)
|
);
|
||||||
.await
|
(
|
||||||
{
|
|
||||||
Ok(bytes) => (
|
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[
|
[
|
||||||
(axum::http::header::CONTENT_TYPE, content_type.to_string()),
|
(axum::http::header::CONTENT_TYPE, content_type.to_string()),
|
||||||
@@ -330,11 +322,9 @@ pub async fn get_export_html(
|
|||||||
format!("attachment; filename=\"{}\"", filename),
|
format!("attachment; filename=\"{}\"", filename),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
bytes,
|
Body::from_stream(stream),
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response()
|
||||||
Err(e) => crate::errors::domain_error_response(e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_activity_feed_html(
|
pub async fn get_activity_feed_html(
|
||||||
|
|||||||
@@ -120,6 +120,12 @@ impl DiaryRepository for Panic {
|
|||||||
async fn get_user_history(&self, _: &UserId) -> Result<Vec<DiaryEntry>, DomainError> {
|
async fn get_user_history(&self, _: &UserId) -> Result<Vec<DiaryEntry>, DomainError> {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
fn stream_user_history(
|
||||||
|
&self,
|
||||||
|
_: UserId,
|
||||||
|
) -> futures::stream::BoxStream<'static, Result<DiaryEntry, DomainError>> {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
async fn get_movie_stats(
|
async fn get_movie_stats(
|
||||||
&self,
|
&self,
|
||||||
_: &MovieId,
|
_: &MovieId,
|
||||||
@@ -379,14 +385,17 @@ impl domain::ports::MovieProfileRepository for Panic {
|
|||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl domain::ports::DiaryExporter for Panic {
|
impl domain::ports::DiaryExporter for Panic {
|
||||||
async fn serialize_entries(
|
fn stream_entries(
|
||||||
&self,
|
&self,
|
||||||
_: &[domain::models::DiaryEntry],
|
_stream: futures::stream::BoxStream<
|
||||||
_: domain::models::ExportFormat,
|
'static,
|
||||||
) -> Result<Vec<u8>, domain::errors::DomainError> {
|
Result<domain::models::DiaryEntry, domain::errors::DomainError>,
|
||||||
panic!()
|
>,
|
||||||
|
_format: domain::models::ExportFormat,
|
||||||
|
) -> futures::stream::BoxStream<'static, Result<bytes::Bytes, domain::errors::DomainError>>
|
||||||
|
{
|
||||||
|
panic!("Panic DiaryExporter called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,14 +165,16 @@ impl domain::ports::UserProfileFieldsRepository for PanicProfileFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PanicExporter;
|
struct PanicExporter;
|
||||||
#[async_trait]
|
|
||||||
impl domain::ports::DiaryExporter for PanicExporter {
|
impl domain::ports::DiaryExporter for PanicExporter {
|
||||||
async fn serialize_entries(
|
fn stream_entries(
|
||||||
&self,
|
&self,
|
||||||
_: &[domain::models::DiaryEntry],
|
_stream: futures::stream::BoxStream<
|
||||||
_: domain::models::ExportFormat,
|
'static,
|
||||||
) -> Result<Vec<u8>, DomainError> {
|
Result<domain::models::DiaryEntry, DomainError>,
|
||||||
panic!()
|
>,
|
||||||
|
_format: domain::models::ExportFormat,
|
||||||
|
) -> futures::stream::BoxStream<'static, Result<bytes::Bytes, DomainError>> {
|
||||||
|
panic!("PanicExporter::stream_entries")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user