Files
movies-diary/crates/application/src/goals/get.rs
Gabriel Kaszewski 57520c00f3
All checks were successful
CI / Check / Test (push) Successful in 39m33s
refactor: move AppContext to presentation crate, structurally enforce boundary
2026-06-11 23:18:28 +02:00

30 lines
697 B
Rust

use std::sync::Arc;
use domain::{
errors::DomainError, models::GoalWithProgress, ports::GoalRepository, value_objects::UserId,
};
use super::queries::GetGoalQuery;
pub async fn execute(
goal: Arc<dyn GoalRepository>,
query: GetGoalQuery,
) -> Result<Option<GoalWithProgress>, DomainError> {
let user_id = UserId::from_uuid(query.user_id);
let found = goal.find_by_user_and_year(&user_id, query.year).await?;
let Some(g) = found else { return Ok(None) };
let current_count = goal.count_reviews_in_year(&user_id, query.year).await?;
Ok(Some(GoalWithProgress {
goal: g,
current_count,
}))
}
#[cfg(test)]
#[path = "tests/get.rs"]
mod tests;