feat: goals — "watch N movies in YEAR" with progress bar
Domain: Goal entity, UserSettings (federation toggle), RemoteGoalEntry.
Ports: GoalRepository, UserSettingsRepository, RemoteGoalRepository.
Adapters: sqlite + postgres repos, migrations, AP content query extensions.
Application: CRUD use cases (create/update/delete/get/list), settings use cases.
API: 7 endpoints (/goals CRUD, /users/{id}/goals, /settings) with utoipa docs.
Federation: GoalObject (Note + goal discriminator), outbound broadcast with
per-user toggle, inbound GoalObjectHandler in CompositeObjectHandler.
SPA: API client + hooks, GoalCard (shadcn Card+Progress+DropdownMenu),
GoalSheet (Drawer), profile integration (editable own, read-only others),
federation toggle in settings (Switch).
Classic HTML: glassmorphic goal card on profile, Frutiger Aero styling.
Progress computed from existing reviews — backwards compatible.
This commit is contained in:
56
crates/application/src/goals/create.rs
Normal file
56
crates/application/src/goals/create.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
events::DomainEvent,
|
||||
models::{Goal, GoalType, GoalWithProgress},
|
||||
value_objects::UserId,
|
||||
};
|
||||
|
||||
use super::commands::CreateGoalCommand;
|
||||
use crate::context::AppContext;
|
||||
|
||||
pub async fn execute(
|
||||
ctx: &AppContext,
|
||||
cmd: CreateGoalCommand,
|
||||
) -> Result<GoalWithProgress, DomainError> {
|
||||
let user_id = UserId::from_uuid(cmd.user_id);
|
||||
|
||||
let existing = ctx
|
||||
.repos
|
||||
.goal
|
||||
.find_by_user_and_year(&user_id, cmd.year)
|
||||
.await?;
|
||||
if existing.is_some() {
|
||||
return Err(DomainError::ValidationError(
|
||||
"Goal already exists for this year".into(),
|
||||
));
|
||||
}
|
||||
|
||||
let goal = Goal::new(
|
||||
user_id.clone(),
|
||||
cmd.year,
|
||||
cmd.target_count,
|
||||
GoalType::Movies,
|
||||
)?;
|
||||
ctx.repos.goal.save(&goal).await?;
|
||||
|
||||
let current_count = ctx
|
||||
.repos
|
||||
.goal
|
||||
.count_reviews_in_year(&user_id, cmd.year)
|
||||
.await?;
|
||||
|
||||
ctx.services
|
||||
.event_publisher
|
||||
.publish(&DomainEvent::GoalCreated {
|
||||
goal_id: goal.id().clone(),
|
||||
user_id,
|
||||
year: cmd.year,
|
||||
target_count: cmd.target_count,
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(GoalWithProgress {
|
||||
goal,
|
||||
current_count,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user