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:
2026-06-08 22:37:52 +02:00
parent 213f9a2433
commit fff5f4af2f
67 changed files with 2747 additions and 28 deletions

View File

@@ -0,0 +1,111 @@
use chrono::NaiveDateTime;
use crate::{
errors::DomainError,
value_objects::{GoalId, UserId},
};
use super::GoalType;
#[derive(Clone, Debug)]
pub struct Goal {
id: GoalId,
user_id: UserId,
year: u16,
target_count: u32,
goal_type: GoalType,
created_at: NaiveDateTime,
}
impl Goal {
pub fn new(
user_id: UserId,
year: u16,
target_count: u32,
goal_type: GoalType,
) -> Result<Self, DomainError> {
if year < 2020 {
return Err(DomainError::ValidationError(
"Goal year must be 2020 or later".into(),
));
}
if target_count < 1 {
return Err(DomainError::ValidationError(
"Target count must be at least 1".into(),
));
}
Ok(Self {
id: GoalId::generate(),
user_id,
year,
target_count,
goal_type,
created_at: chrono::Utc::now().naive_utc(),
})
}
pub fn from_persistence(
id: GoalId,
user_id: UserId,
year: u16,
target_count: u32,
goal_type: GoalType,
created_at: NaiveDateTime,
) -> Self {
Self {
id,
user_id,
year,
target_count,
goal_type,
created_at,
}
}
pub fn update_target(&mut self, target_count: u32) -> Result<(), DomainError> {
if target_count < 1 {
return Err(DomainError::ValidationError(
"Target count must be at least 1".into(),
));
}
self.target_count = target_count;
Ok(())
}
pub fn id(&self) -> &GoalId {
&self.id
}
pub fn user_id(&self) -> &UserId {
&self.user_id
}
pub fn year(&self) -> u16 {
self.year
}
pub fn target_count(&self) -> u32 {
self.target_count
}
pub fn goal_type(&self) -> &GoalType {
&self.goal_type
}
pub fn created_at(&self) -> &NaiveDateTime {
&self.created_at
}
}
pub struct GoalWithProgress {
pub goal: Goal,
pub current_count: u32,
}
impl GoalWithProgress {
pub fn percentage(&self) -> f64 {
if self.goal.target_count == 0 {
return 100.0;
}
((self.current_count as f64 / self.goal.target_count as f64) * 100.0).min(100.0)
}
pub fn is_complete(&self) -> bool {
self.current_count >= self.goal.target_count
}
}