diff --git a/crates/presentation/src/handlers/diary.rs b/crates/presentation/src/handlers/diary.rs index c71cf29..fd88571 100644 --- a/crates/presentation/src/handlers/diary.rs +++ b/crates/presentation/src/handlers/diary.rs @@ -1,5 +1,6 @@ use axum::{ Form, Json, + body::Body, extract::{Extension, Path, Query, State}, http::StatusCode, response::{IntoResponse, Redirect}, @@ -147,30 +148,23 @@ pub async fn export_diary( user_id: user.0.value(), format, }; - match export_diary_uc::execute( + let stream = export_diary_uc::execute( &state.app_ctx.repos.diary, &state.app_ctx.services.diary_exporter, query, + ); + ( + StatusCode::OK, + [ + (axum::http::header::CONTENT_TYPE, content_type.to_string()), + ( + axum::http::header::CONTENT_DISPOSITION, + format!("attachment; filename=\"{}\"", filename), + ), + ], + Body::from_stream(stream), ) - .await - { - Ok(bytes) => ( - StatusCode::OK, - [ - (axum::http::header::CONTENT_TYPE, content_type.to_string()), - ( - axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{}\"", filename), - ), - ], - bytes, - ) - .into_response(), - Err(e) => { - tracing::error!("export error: {:?}", e); - StatusCode::INTERNAL_SERVER_ERROR.into_response() - } - } + .into_response() } #[utoipa::path( @@ -314,27 +308,23 @@ pub async fn get_export_html( user_id: user_id.value(), format, }; - match export_diary_uc::execute( + let stream = export_diary_uc::execute( &state.app_ctx.repos.diary, &state.app_ctx.services.diary_exporter, query, + ); + ( + StatusCode::OK, + [ + (axum::http::header::CONTENT_TYPE, content_type.to_string()), + ( + axum::http::header::CONTENT_DISPOSITION, + format!("attachment; filename=\"{}\"", filename), + ), + ], + Body::from_stream(stream), ) - .await - { - Ok(bytes) => ( - StatusCode::OK, - [ - (axum::http::header::CONTENT_TYPE, content_type.to_string()), - ( - axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{}\"", filename), - ), - ], - bytes, - ) - .into_response(), - Err(e) => crate::errors::domain_error_response(e), - } + .into_response() } pub async fn get_activity_feed_html( diff --git a/crates/presentation/src/tests/extractors.rs b/crates/presentation/src/tests/extractors.rs index e1bb397..060b343 100644 --- a/crates/presentation/src/tests/extractors.rs +++ b/crates/presentation/src/tests/extractors.rs @@ -120,6 +120,12 @@ impl DiaryRepository for Panic { async fn get_user_history(&self, _: &UserId) -> Result, DomainError> { panic!() } + fn stream_user_history( + &self, + _: UserId, + ) -> futures::stream::BoxStream<'static, Result> { + panic!() + } async fn get_movie_stats( &self, _: &MovieId, @@ -379,14 +385,17 @@ impl domain::ports::MovieProfileRepository for Panic { Ok(vec![]) } } -#[async_trait::async_trait] impl domain::ports::DiaryExporter for Panic { - async fn serialize_entries( + fn stream_entries( &self, - _: &[domain::models::DiaryEntry], - _: domain::models::ExportFormat, - ) -> Result, domain::errors::DomainError> { - panic!() + _stream: futures::stream::BoxStream< + 'static, + Result, + >, + _format: domain::models::ExportFormat, + ) -> futures::stream::BoxStream<'static, Result> + { + panic!("Panic DiaryExporter called") } } diff --git a/crates/presentation/tests/api_test.rs b/crates/presentation/tests/api_test.rs index fe62d27..d757585 100644 --- a/crates/presentation/tests/api_test.rs +++ b/crates/presentation/tests/api_test.rs @@ -165,14 +165,16 @@ impl domain::ports::UserProfileFieldsRepository for PanicProfileFields { } struct PanicExporter; -#[async_trait] impl domain::ports::DiaryExporter for PanicExporter { - async fn serialize_entries( + fn stream_entries( &self, - _: &[domain::models::DiaryEntry], - _: domain::models::ExportFormat, - ) -> Result, DomainError> { - panic!() + _stream: futures::stream::BoxStream< + 'static, + Result, + >, + _format: domain::models::ExportFormat, + ) -> futures::stream::BoxStream<'static, Result> { + panic!("PanicExporter::stream_entries") } }