export feature
This commit is contained in:
@@ -1,23 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{errors::DomainError, value_objects::UserId};
|
||||
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
ports::{DiaryExporter, DiaryRepository},
|
||||
};
|
||||
use crate::{commands::ExportCommand, context::AppContext};
|
||||
|
||||
use crate::commands::ExportCommand;
|
||||
|
||||
pub struct ExportDiary {
|
||||
repository: Arc<dyn DiaryRepository>,
|
||||
exporter: Arc<dyn DiaryExporter>,
|
||||
}
|
||||
|
||||
impl ExportDiary {
|
||||
pub async fn execute(&self, req: ExportCommand) -> Result<Vec<u8>, DomainError> {
|
||||
// 1. fetch all diary entries for the user
|
||||
// 2. delegate serialization to the port (exporter)
|
||||
|
||||
// Return bytes of the exported diary, which can be written to a file or returned in an HTTP response
|
||||
Ok(vec![])
|
||||
}
|
||||
pub async fn execute(ctx: &AppContext, cmd: ExportCommand) -> Result<Vec<u8>, DomainError> {
|
||||
let entries = ctx
|
||||
.diary_repository
|
||||
.get_user_history(&UserId::from_uuid(cmd.user_id))
|
||||
.await?;
|
||||
ctx.diary_exporter
|
||||
.serialize_entries(&entries, cmd.format)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user