23
crates/application/src/use_cases/get_review_history.rs
Normal file
23
crates/application/src/use_cases/get_review_history.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
models::ReviewHistory,
|
||||
services::review_history::{ReviewHistoryAnalyzer, Trend},
|
||||
value_objects::MovieId,
|
||||
};
|
||||
|
||||
use crate::{context::AppContext, queries::GetReviewHistoryQuery};
|
||||
|
||||
pub async fn execute(
|
||||
ctx: &AppContext,
|
||||
query: GetReviewHistoryQuery,
|
||||
) -> Result<(ReviewHistory, Trend), DomainError> {
|
||||
let movie_id = MovieId::from_uuid(query.movie_id);
|
||||
|
||||
let mut history = ctx.repository.get_review_history(&movie_id).await?;
|
||||
|
||||
let trend = ReviewHistoryAnalyzer::rating_trend(&history)?;
|
||||
|
||||
ReviewHistoryAnalyzer::sort_chronologically(&mut history);
|
||||
|
||||
Ok((history, trend))
|
||||
}
|
||||
Reference in New Issue
Block a user