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:
111
crates/domain/src/models/goal.rs
Normal file
111
crates/domain/src/models/goal.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,12 @@ pub mod watchlist;
|
||||
pub use watchlist::{WatchlistEntry, WatchlistWithMovie};
|
||||
pub mod remote_watchlist;
|
||||
pub use remote_watchlist::RemoteWatchlistEntry;
|
||||
pub mod goal;
|
||||
pub use goal::{Goal, GoalWithProgress};
|
||||
pub mod user_settings;
|
||||
pub use user_settings::UserSettings;
|
||||
pub mod remote_goal;
|
||||
pub use remote_goal::RemoteGoalEntry;
|
||||
pub mod watch_event;
|
||||
pub mod wrapup;
|
||||
pub use watch_event::{
|
||||
@@ -38,6 +44,32 @@ pub use search::{
|
||||
SearchResults,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum GoalType {
|
||||
Movies,
|
||||
}
|
||||
|
||||
impl GoalType {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Movies => "movies",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for GoalType {
|
||||
type Err = DomainError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"movies" => Ok(Self::Movies),
|
||||
other => Err(DomainError::ValidationError(format!(
|
||||
"Unknown goal type: {other}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub enum SortDirection {
|
||||
#[default]
|
||||
|
||||
11
crates/domain/src/models/remote_goal.rs
Normal file
11
crates/domain/src/models/remote_goal.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RemoteGoalEntry {
|
||||
pub ap_id: String,
|
||||
pub actor_url: String,
|
||||
pub year: u16,
|
||||
pub target_count: u32,
|
||||
pub current_count: u32,
|
||||
pub received_at: DateTime<Utc>,
|
||||
}
|
||||
35
crates/domain/src/models/user_settings.rs
Normal file
35
crates/domain/src/models/user_settings.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use crate::value_objects::UserId;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserSettings {
|
||||
user_id: UserId,
|
||||
federate_goals: bool,
|
||||
}
|
||||
|
||||
impl UserSettings {
|
||||
pub fn new(user_id: UserId) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
federate_goals: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_persistence(user_id: UserId, federate_goals: bool) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
federate_goals,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_federate_goals(&mut self, value: bool) {
|
||||
self.federate_goals = value;
|
||||
}
|
||||
|
||||
pub fn user_id(&self) -> &UserId {
|
||||
&self.user_id
|
||||
}
|
||||
|
||||
pub fn federate_goals(&self) -> bool {
|
||||
self.federate_goals
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user