diff --git a/crates/adapters/activitypub/src/event_handler.rs b/crates/adapters/activitypub/src/event_handler.rs index 7bdb2c3..0a83a64 100644 --- a/crates/adapters/activitypub/src/event_handler.rs +++ b/crates/adapters/activitypub/src/event_handler.rs @@ -3,7 +3,7 @@ use domain::ports::EventHandler; use domain::{ errors::DomainError, events::DomainEvent, - ports::{MovieRepository, ReviewRepository, WatchlistRepository}, + ports::{MovieRepository, ReviewRepository}, value_objects::{ReviewId, UserId}, }; use std::sync::Arc; @@ -17,7 +17,6 @@ pub struct ActivityPubEventHandler { ap_service: Arc, movie_repository: Arc, review_repository: Arc, - watchlist_repository: Arc, base_url: String, } @@ -26,14 +25,12 @@ impl ActivityPubEventHandler { ap_service: Arc, movie_repository: Arc, review_repository: Arc, - watchlist_repository: Arc, base_url: String, ) -> Self { Self { ap_service, movie_repository, review_repository, - watchlist_repository, base_url, } } diff --git a/crates/adapters/activitypub/src/lib.rs b/crates/adapters/activitypub/src/lib.rs index 20a617c..4f36489 100644 --- a/crates/adapters/activitypub/src/lib.rs +++ b/crates/adapters/activitypub/src/lib.rs @@ -30,7 +30,6 @@ pub async fn wire( federation_repo: std::sync::Arc, review_store: std::sync::Arc, remote_watchlist_repo: std::sync::Arc, - watchlist_repo: std::sync::Arc, user_repo: std::sync::Arc, movie_repo: std::sync::Arc, review_repo: std::sync::Arc, @@ -70,7 +69,6 @@ pub async fn wire( std::sync::Arc::clone(&concrete), movie_repo, review_repo, - watchlist_repo, base_url, )) as std::sync::Arc; diff --git a/crates/application/src/use_cases/get_remote_watchlist.rs b/crates/application/src/use_cases/get_remote_watchlist.rs new file mode 100644 index 0000000..4be235c --- /dev/null +++ b/crates/application/src/use_cases/get_remote_watchlist.rs @@ -0,0 +1,7 @@ +use domain::{errors::DomainError, models::RemoteWatchlistEntry}; + +use crate::context::AppContext; + +pub async fn execute(ctx: &AppContext, uuid: uuid::Uuid) -> Result, DomainError> { + ctx.remote_watchlist_repository.get_by_derived_uuid(uuid).await +} diff --git a/crates/application/src/use_cases/mod.rs b/crates/application/src/use_cases/mod.rs index 05f9156..1d9ae0e 100644 --- a/crates/application/src/use_cases/mod.rs +++ b/crates/application/src/use_cases/mod.rs @@ -28,3 +28,5 @@ pub mod add_to_watchlist; pub mod remove_from_watchlist; pub mod get_watchlist; pub mod is_on_watchlist; +#[cfg(feature = "federation")] +pub mod get_remote_watchlist; diff --git a/crates/presentation/src/handlers/html.rs b/crates/presentation/src/handlers/html.rs index ba0b857..e196744 100644 --- a/crates/presentation/src/handlers/html.rs +++ b/crates/presentation/src/handlers/html.rs @@ -10,13 +10,16 @@ use chrono::Utc; use uuid::Uuid; #[cfg(feature = "federation")] -use application::ports::{ - BlockedActorEntry, BlockedActorsPageData, BlockedDomainEntry, BlockedDomainsPageData, - FollowersPageData, FollowingPageData, +use application::{ + ports::{ + BlockedActorEntry, BlockedActorsPageData, BlockedDomainEntry, BlockedDomainsPageData, + FollowersPageData, FollowingPageData, + }, + use_cases::get_remote_watchlist, }; use application::{ commands::{AddToWatchlistCommand, DeleteReviewCommand, MovieInput, RegisterCommand, RemoveFromWatchlistCommand}, - queries::{ExportQuery, GetMovieSocialPageQuery, GetWatchlistQuery, LoginQuery}, + queries::{ExportQuery, GetMovieSocialPageQuery, GetWatchlistQuery, IsOnWatchlistQuery, LoginQuery}, ports::{ HtmlPageContext, LoginPageData, MovieDetailPageData, NewReviewPageData, ProfileSettingsPageData, RegisterPageData, RemoteActorView, WatchlistDisplayEntry, @@ -24,7 +27,7 @@ use application::{ }, use_cases::{ add_to_watchlist, delete_review, export_diary as export_diary_uc, get_movie_social_page, - get_watchlist, log_review, login as login_uc, register as register_uc, + get_watchlist, is_on_watchlist, log_review, login as login_uc, register as register_uc, remove_from_watchlist, update_profile, }, }; @@ -975,10 +978,12 @@ pub async fn get_movie_detail( let has_more = result.reviews.offset + result.reviews.limit < result.reviews.total_count as u32; let on_watchlist = match &user_id { - Some(uid) => state.app_ctx.watchlist_repository - .contains(uid, &domain::value_objects::MovieId::from_uuid(movie_id)) - .await - .unwrap_or(false), + Some(uid) => is_on_watchlist::execute( + &state.app_ctx, + IsOnWatchlistQuery { user_id: uid.value(), movie_id }, + ) + .await + .unwrap_or(false), None => false, }; let data = MovieDetailPageData { @@ -1056,8 +1061,7 @@ pub async fn get_watchlist_page( } else { #[cfg(feature = "federation")] { - let remote_entries = state.app_ctx.remote_watchlist_repository - .get_by_derived_uuid(owner_id) + let remote_entries = get_remote_watchlist::execute(&state.app_ctx, owner_id) .await .unwrap_or_default(); let display: Vec = remote_entries.into_iter().map(|e| { diff --git a/crates/presentation/src/main.rs b/crates/presentation/src/main.rs index 947f40d..32a1fe5 100644 --- a/crates/presentation/src/main.rs +++ b/crates/presentation/src/main.rs @@ -90,7 +90,6 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> { federation_repo, review_store, remote_watchlist_repo.clone(), - Arc::clone(&watchlist_repository), Arc::clone(&user_repository), Arc::clone(&movie_repository), Arc::clone(&review_repository), diff --git a/crates/worker/src/main.rs b/crates/worker/src/main.rs index 6dd1a9e..488f5f3 100644 --- a/crates/worker/src/main.rs +++ b/crates/worker/src/main.rs @@ -170,7 +170,6 @@ async fn main() -> anyhow::Result<()> { fed_federation_repo, fed_review_store, fed_remote_watchlist_repo, - Arc::clone(&ctx.watchlist_repository), fed_user_repo, fed_movie_repo, fed_review_repo,