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:
@@ -3,7 +3,9 @@ use chrono::NaiveDateTime;
|
||||
|
||||
use crate::{
|
||||
errors::DomainError,
|
||||
value_objects::{ExternalMetadataId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId},
|
||||
value_objects::{
|
||||
ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -88,6 +90,23 @@ pub enum DomainEvent {
|
||||
PosterSynced {
|
||||
movie_id: MovieId,
|
||||
},
|
||||
GoalCreated {
|
||||
goal_id: GoalId,
|
||||
user_id: UserId,
|
||||
year: u16,
|
||||
target_count: u32,
|
||||
},
|
||||
GoalUpdated {
|
||||
goal_id: GoalId,
|
||||
user_id: UserId,
|
||||
year: u16,
|
||||
target_count: u32,
|
||||
},
|
||||
GoalDeleted {
|
||||
goal_id: GoalId,
|
||||
user_id: UserId,
|
||||
year: u16,
|
||||
},
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,17 @@ use crate::{
|
||||
models::wrapup::WrapUpReport,
|
||||
models::{
|
||||
AnnotatedRow, DiaryEntry, DiaryFilter, EntityType, ExportFormat, ExternalPersonId,
|
||||
FeedEntry, FieldMapping, FileFormat, ImportError, ImportProfile, ImportSession,
|
||||
FeedEntry, FieldMapping, FileFormat, Goal, ImportError, ImportProfile, ImportSession,
|
||||
IndexableDocument, Movie, MovieFilter, MovieProfile, MovieStats, MovieSummary, ParsedFile,
|
||||
ParsedPlaybackEvent, Person, PersonCredits, PersonId, RemoteWatchlistEntry, Review,
|
||||
ReviewHistory, SearchQuery, SearchResults, User, UserStats, UserSummary, UserTrends,
|
||||
WatchEvent, WatchEventStatus, WatchlistEntry, WatchlistWithMovie, WebhookToken,
|
||||
ParsedPlaybackEvent, Person, PersonCredits, PersonId, RemoteGoalEntry,
|
||||
RemoteWatchlistEntry, Review, ReviewHistory, SearchQuery, SearchResults, User,
|
||||
UserSettings, UserStats, UserSummary, UserTrends, WatchEvent, WatchEventStatus,
|
||||
WatchlistEntry, WatchlistWithMovie, WebhookToken,
|
||||
collections::{self, PageParams, Paginated},
|
||||
wrapup::{DateRange, WrapUpRecord, WrapUpScope, WrapUpStatus},
|
||||
},
|
||||
value_objects::{
|
||||
Email, ExternalMetadataId, ImportProfileId, ImportSessionId, MovieId, MovieTitle,
|
||||
Email, ExternalMetadataId, GoalId, ImportProfileId, ImportSessionId, MovieId, MovieTitle,
|
||||
PasswordHash, PosterUrl, ReleaseYear, ReviewId, UserId, Username, WatchEventId,
|
||||
WebhookTokenId, WrapUpId,
|
||||
},
|
||||
@@ -411,6 +412,41 @@ pub trait RemoteWatchlistRepository: Send + Sync {
|
||||
) -> Result<Vec<RemoteWatchlistEntry>, DomainError>;
|
||||
}
|
||||
|
||||
// ── Goals ────────────────────────────────────────────────────────────────────
|
||||
|
||||
#[async_trait]
|
||||
pub trait GoalRepository: Send + Sync {
|
||||
async fn save(&self, goal: &Goal) -> Result<(), DomainError>;
|
||||
async fn update(&self, goal: &Goal) -> Result<(), DomainError>;
|
||||
async fn delete(&self, id: &GoalId, user_id: &UserId) -> Result<(), DomainError>;
|
||||
async fn find_by_user_and_year(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
year: u16,
|
||||
) -> Result<Option<Goal>, DomainError>;
|
||||
async fn list_for_user(&self, user_id: &UserId) -> Result<Vec<Goal>, DomainError>;
|
||||
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait UserSettingsRepository: Send + Sync {
|
||||
async fn get(&self, user_id: &UserId) -> Result<UserSettings, DomainError>;
|
||||
async fn save(&self, settings: &UserSettings) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait RemoteGoalRepository: Send + Sync {
|
||||
async fn save(&self, entry: RemoteGoalEntry) -> Result<(), DomainError>;
|
||||
async fn update_by_ap_id(
|
||||
&self,
|
||||
ap_id: &str,
|
||||
target: u32,
|
||||
current: u32,
|
||||
) -> Result<(), DomainError>;
|
||||
async fn remove_by_ap_id(&self, ap_id: &str, actor_url: &str) -> Result<(), DomainError>;
|
||||
async fn get_by_actor_url(&self, actor_url: &str) -> Result<Vec<RemoteGoalEntry>, DomainError>;
|
||||
}
|
||||
|
||||
/// Read-only query port used exclusively by the ActivityPub adapter.
|
||||
/// Consolidates all reads the AP adapter needs so it never touches write repositories.
|
||||
#[async_trait]
|
||||
@@ -442,6 +478,14 @@ pub trait LocalApContentQuery: Send + Sync {
|
||||
before: Option<chrono::NaiveDateTime>,
|
||||
limit: usize,
|
||||
) -> Result<Vec<DiaryEntry>, DomainError>;
|
||||
|
||||
async fn get_user_federate_goals(&self, user_id: &UserId) -> Result<bool, DomainError>;
|
||||
|
||||
async fn get_goal_with_progress(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
year: u16,
|
||||
) -> Result<Option<(Goal, u32)>, DomainError>;
|
||||
}
|
||||
|
||||
// ── Media server integration ──────────────────────────────────────────────────
|
||||
|
||||
@@ -1240,3 +1240,70 @@ impl WrapUpRepository for PanicWrapUpRepository {
|
||||
panic!("PanicWrapUpRepository called")
|
||||
}
|
||||
}
|
||||
|
||||
// ── Noop Goal/Settings repos ────────────────────────────────────────────────
|
||||
|
||||
pub struct NoopGoalRepository;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ports::GoalRepository for NoopGoalRepository {
|
||||
async fn save(&self, _: &crate::models::Goal) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn update(&self, _: &crate::models::Goal) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn delete(
|
||||
&self,
|
||||
_: &crate::value_objects::GoalId,
|
||||
_: &UserId,
|
||||
) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn find_by_user_and_year(
|
||||
&self,
|
||||
_: &UserId,
|
||||
_: u16,
|
||||
) -> Result<Option<crate::models::Goal>, DomainError> {
|
||||
Ok(None)
|
||||
}
|
||||
async fn list_for_user(&self, _: &UserId) -> Result<Vec<crate::models::Goal>, DomainError> {
|
||||
Ok(vec![])
|
||||
}
|
||||
async fn count_reviews_in_year(&self, _: &UserId, _: u16) -> Result<u32, DomainError> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NoopUserSettingsRepository;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ports::UserSettingsRepository for NoopUserSettingsRepository {
|
||||
async fn get(&self, user_id: &UserId) -> Result<crate::models::UserSettings, DomainError> {
|
||||
Ok(crate::models::UserSettings::new(user_id.clone()))
|
||||
}
|
||||
async fn save(&self, _: &crate::models::UserSettings) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NoopRemoteGoalRepository;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ports::RemoteGoalRepository for NoopRemoteGoalRepository {
|
||||
async fn save(&self, _: crate::models::RemoteGoalEntry) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn update_by_ap_id(&self, _: &str, _: u32, _: u32) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn remove_by_ap_id(&self, _: &str, _: &str) -> Result<(), DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
async fn get_by_actor_url(
|
||||
&self,
|
||||
_: &str,
|
||||
) -> Result<Vec<crate::models::RemoteGoalEntry>, DomainError> {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ uuid_id!(WatchlistEntryId);
|
||||
uuid_id!(WatchEventId);
|
||||
uuid_id!(WebhookTokenId);
|
||||
uuid_id!(WrapUpId);
|
||||
uuid_id!(GoalId);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ExternalMetadataId(String);
|
||||
|
||||
Reference in New Issue
Block a user