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

@@ -1,13 +1,13 @@
use std::sync::Arc;
use domain::ports::{
AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher,
AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, GoalRepository,
ImportProfileRepository, ImportSessionRepository, MetadataClient, MovieProfileRepository,
MovieRepository, ObjectStorage, PasswordHasher, PersonCommand, PersonQuery,
PosterFetcherClient, RemoteWatchlistRepository, ReviewRepository, SearchCommand, SearchPort,
SocialQueryPort, StatsRepository, UserProfileFieldsRepository, UserRepository,
WatchEventRepository, WatchlistRepository, WebhookTokenRepository, WrapUpRepository,
WrapUpStatsQuery, WrapUpVideoRenderer,
PosterFetcherClient, RemoteGoalRepository, RemoteWatchlistRepository, ReviewRepository,
SearchCommand, SearchPort, SocialQueryPort, StatsRepository, UserProfileFieldsRepository,
UserRepository, UserSettingsRepository, WatchEventRepository, WatchlistRepository,
WebhookTokenRepository, WrapUpRepository, WrapUpStatsQuery, WrapUpVideoRenderer,
};
use crate::config::AppConfig;
@@ -34,6 +34,9 @@ pub struct Repositories {
pub social_query: Arc<dyn SocialQueryPort>,
pub wrapup_stats: Arc<dyn WrapUpStatsQuery>,
pub wrapup_repo: Arc<dyn WrapUpRepository>,
pub goal: Arc<dyn GoalRepository>,
pub user_settings: Arc<dyn UserSettingsRepository>,
pub remote_goal: Arc<dyn RemoteGoalRepository>,
}
#[derive(Clone)]

View File

@@ -0,0 +1,18 @@
use uuid::Uuid;
pub struct CreateGoalCommand {
pub user_id: Uuid,
pub year: u16,
pub target_count: u32,
}
pub struct UpdateGoalCommand {
pub user_id: Uuid,
pub year: u16,
pub target_count: u32,
}
pub struct DeleteGoalCommand {
pub user_id: Uuid,
pub year: u16,
}

View 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,
})
}

View File

@@ -0,0 +1,28 @@
use domain::{errors::DomainError, events::DomainEvent, value_objects::UserId};
use super::commands::DeleteGoalCommand;
use crate::context::AppContext;
pub async fn execute(ctx: &AppContext, cmd: DeleteGoalCommand) -> Result<(), DomainError> {
let user_id = UserId::from_uuid(cmd.user_id);
let goal = ctx
.repos
.goal
.find_by_user_and_year(&user_id, cmd.year)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Goal for year {}", cmd.year)))?;
ctx.repos.goal.delete(goal.id(), &user_id).await?;
ctx.services
.event_publisher
.publish(&DomainEvent::GoalDeleted {
goal_id: goal.id().clone(),
user_id,
year: cmd.year,
})
.await?;
Ok(())
}

View File

@@ -0,0 +1,30 @@
use domain::{errors::DomainError, models::GoalWithProgress, value_objects::UserId};
use super::queries::GetGoalQuery;
use crate::context::AppContext;
pub async fn execute(
ctx: &AppContext,
query: GetGoalQuery,
) -> Result<Option<GoalWithProgress>, DomainError> {
let user_id = UserId::from_uuid(query.user_id);
let goal = ctx
.repos
.goal
.find_by_user_and_year(&user_id, query.year)
.await?;
let Some(goal) = goal else { return Ok(None) };
let current_count = ctx
.repos
.goal
.count_reviews_in_year(&user_id, query.year)
.await?;
Ok(Some(GoalWithProgress {
goal,
current_count,
}))
}

View File

@@ -0,0 +1,27 @@
use domain::{errors::DomainError, models::GoalWithProgress, value_objects::UserId};
use super::queries::ListGoalsQuery;
use crate::context::AppContext;
pub async fn execute(
ctx: &AppContext,
query: ListGoalsQuery,
) -> Result<Vec<GoalWithProgress>, DomainError> {
let user_id = UserId::from_uuid(query.user_id);
let goals = ctx.repos.goal.list_for_user(&user_id).await?;
let mut result = Vec::with_capacity(goals.len());
for goal in goals {
let current_count = ctx
.repos
.goal
.count_reviews_in_year(&user_id, goal.year())
.await?;
result.push(GoalWithProgress {
goal,
current_count,
});
}
Ok(result)
}

View File

@@ -0,0 +1,7 @@
pub mod commands;
pub mod create;
pub mod delete;
pub mod get;
pub mod list;
pub mod queries;
pub mod update;

View File

@@ -0,0 +1,10 @@
use uuid::Uuid;
pub struct GetGoalQuery {
pub user_id: Uuid,
pub year: u16,
}
pub struct ListGoalsQuery {
pub user_id: Uuid,
}

View File

@@ -0,0 +1,44 @@
use domain::{
errors::DomainError, events::DomainEvent, models::GoalWithProgress, value_objects::UserId,
};
use super::commands::UpdateGoalCommand;
use crate::context::AppContext;
pub async fn execute(
ctx: &AppContext,
cmd: UpdateGoalCommand,
) -> Result<GoalWithProgress, DomainError> {
let user_id = UserId::from_uuid(cmd.user_id);
let mut goal = ctx
.repos
.goal
.find_by_user_and_year(&user_id, cmd.year)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Goal for year {}", cmd.year)))?;
goal.update_target(cmd.target_count)?;
ctx.repos.goal.update(&goal).await?;
let current_count = ctx
.repos
.goal
.count_reviews_in_year(&user_id, cmd.year)
.await?;
ctx.services
.event_publisher
.publish(&DomainEvent::GoalUpdated {
goal_id: goal.id().clone(),
user_id,
year: cmd.year,
target_count: cmd.target_count,
})
.await?;
Ok(GoalWithProgress {
goal,
current_count,
})
}

View File

@@ -6,6 +6,7 @@ pub mod worker;
pub mod auth;
pub mod diary;
pub mod goals;
pub mod import;
pub mod integrations;
pub mod movies;

View File

@@ -172,6 +172,9 @@ impl TestContextBuilder {
social_query: Arc::new(NoopSocialQueryPort),
wrapup_stats: self.wrapup_stats,
wrapup_repo: self.wrapup_repo,
goal: Arc::new(domain::testing::NoopGoalRepository),
user_settings: Arc::new(domain::testing::NoopUserSettingsRepository),
remote_goal: Arc::new(domain::testing::NoopRemoteGoalRepository),
},
services: Services {
auth: self.auth_service,

View File

@@ -63,6 +63,9 @@ impl EventHandler for RecordingHandler {
DomainEvent::WrapUpCompleted { .. } => "wrapup_completed",
DomainEvent::SearchReindexRequested => "search_reindex",
DomainEvent::PosterSynced { .. } => "poster_synced",
DomainEvent::GoalCreated { .. }
| DomainEvent::GoalUpdated { .. }
| DomainEvent::GoalDeleted { .. } => "goal",
};
self.calls.lock().unwrap().push(label);
Ok(())

View File

@@ -0,0 +1,8 @@
use domain::{errors::DomainError, models::UserSettings, value_objects::UserId};
use crate::context::AppContext;
pub async fn execute(ctx: &AppContext, user_id: uuid::Uuid) -> Result<UserSettings, DomainError> {
let uid = UserId::from_uuid(user_id);
ctx.repos.user_settings.get(&uid).await
}

View File

@@ -1,7 +1,9 @@
pub mod commands;
pub mod get_current_profile;
pub mod get_profile;
pub mod get_settings;
pub mod get_users;
pub mod queries;
pub mod update_profile;
pub mod update_profile_fields;
pub mod update_settings;

View File

@@ -0,0 +1,15 @@
use domain::{errors::DomainError, value_objects::UserId};
use crate::context::AppContext;
pub struct UpdateUserSettingsCommand {
pub user_id: uuid::Uuid,
pub federate_goals: bool,
}
pub async fn execute(ctx: &AppContext, cmd: UpdateUserSettingsCommand) -> Result<(), DomainError> {
let uid = UserId::from_uuid(cmd.user_id);
let mut settings = ctx.repos.user_settings.get(&uid).await?;
settings.set_federate_goals(cmd.federate_goals);
ctx.repos.user_settings.save(&settings).await
}