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:
2026-05-31 05:00:34 +02:00
parent d62d8157a8
commit fa36bb8c0e
43 changed files with 305 additions and 168 deletions

View File

@@ -3,6 +3,7 @@ use api_types::{
requests::{LoginRequest, RegisterRequest},
responses::{AuthResponse, UserResponse},
};
use application::identity::{RegisterUserCommand, LoginUserCommand, GetProfileQuery};
use crate::{errors::AppError, extractors::{JwtClaims, ValidatedJson}, state::AppState};
#[utoipa::path(
@@ -18,7 +19,12 @@ pub async fn register(
State(state): State<AppState>,
ValidatedJson(req): ValidatedJson<RegisterRequest>,
) -> Result<(StatusCode, Json<AuthResponse>), AppError> {
let user = state.register_uc.execute(&req.email, &req.password).await?;
let cmd = RegisterUserCommand {
username: req.username,
email: req.email,
password: req.password,
};
let user = state.register_handler.execute(cmd).await?;
let token = state.token_issuer.issue(&user.id, "user").await.map_err(AppError::from)?;
Ok((StatusCode::CREATED, Json(AuthResponse { token, user: UserResponse::from_domain(&user) })))
}
@@ -35,7 +41,11 @@ pub async fn login(
State(state): State<AppState>,
ValidatedJson(req): ValidatedJson<LoginRequest>,
) -> Result<Json<AuthResponse>, AppError> {
let (user, token) = state.login_uc.execute(&req.email, &req.password).await?;
let cmd = LoginUserCommand {
email: req.email,
password: req.password,
};
let (user, token) = state.login_handler.execute(cmd).await?;
Ok(Json(AuthResponse { token, user: UserResponse::from_domain(&user) }))
}
@@ -51,6 +61,7 @@ pub async fn me(
State(state): State<AppState>,
claims: JwtClaims,
) -> Result<Json<UserResponse>, AppError> {
let user = state.get_profile_uc.execute(&claims.user_id).await?;
let query = GetProfileQuery { user_id: claims.user_id };
let user = state.get_profile_handler.execute(query).await?;
Ok(Json(UserResponse::from_domain(&user)))
}