refactor: restructure application to CQRS, update api-types + presentation
- application: replace flat use_cases/ with identity/{commands,queries}/ and organization/commands/
- each use case now split into Command/Query struct + Handler struct
- api-types: add username to RegisterRequest/UserResponse, add CreateAlbumRequest/AlbumResponse
- presentation: update state, handlers, factory to use new handler types
- tests: restructured to match CQRS module layout, added get_profile tests
This commit is contained in:
32
crates/application/src/organization/commands/create_album.rs
Normal file
32
crates/application/src/organization/commands/create_album.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use std::sync::Arc;
|
||||
use domain::{
|
||||
entities::Album,
|
||||
errors::DomainError,
|
||||
ports::AlbumRepository,
|
||||
value_objects::SystemId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct CreateAlbumCommand {
|
||||
pub title: String,
|
||||
pub creator_id: SystemId,
|
||||
}
|
||||
|
||||
pub struct CreateAlbumHandler {
|
||||
album_repo: Arc<dyn AlbumRepository>,
|
||||
}
|
||||
|
||||
impl CreateAlbumHandler {
|
||||
pub fn new(album_repo: Arc<dyn AlbumRepository>) -> Self {
|
||||
Self { album_repo }
|
||||
}
|
||||
|
||||
pub async fn execute(&self, cmd: CreateAlbumCommand) -> Result<Album, DomainError> {
|
||||
if cmd.title.is_empty() {
|
||||
return Err(DomainError::Validation("Album title must not be empty".to_string()));
|
||||
}
|
||||
let album = Album::new(&cmd.title, cmd.creator_id);
|
||||
self.album_repo.save(&album).await?;
|
||||
Ok(album)
|
||||
}
|
||||
}
|
||||
3
crates/application/src/organization/commands/mod.rs
Normal file
3
crates/application/src/organization/commands/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod create_album;
|
||||
|
||||
pub use create_album::{CreateAlbumCommand, CreateAlbumHandler};
|
||||
3
crates/application/src/organization/mod.rs
Normal file
3
crates/application/src/organization/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod commands;
|
||||
|
||||
pub use commands::{CreateAlbumCommand, CreateAlbumHandler};
|
||||
Reference in New Issue
Block a user