From 6c45a806235fa4bd8ebdb16e8ad067c93a504674 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Wed, 13 May 2026 18:18:22 +0200 Subject: [PATCH] fix: pass watchlist status to anime detail page Anime detail page never looked up or passed the user's watchlist status, so the dropdown always showed 'Add to Watchlist'. Now queries watch_list_entry and passes Status and WatchlistIDs. --- internal/anime/handler/handler.go | 10 ++++++++++ internal/domain/watchlist.go | 2 ++ internal/watchlist/repository/repository.go | 4 ++++ internal/watchlist/service/service.go | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/internal/anime/handler/handler.go b/internal/anime/handler/handler.go index 72e4a17..a3818cd 100644 --- a/internal/anime/handler/handler.go +++ b/internal/anime/handler/handler.go @@ -253,9 +253,17 @@ func (h *AnimeHandler) HandleAnimeDetails(c *gin.Context) { } user, _ := c.Get("User") + status := "" + var watchlistIDs []int64 ep := 1 var cwSeconds float64 if u, ok := user.(*domain.User); ok { + entry, err := h.watchlistSvc.GetWatchListEntry(c.Request.Context(), u.ID, int64(id)) + if err == nil { + status = entry.Status + watchlistIDs = []int64{entry.AnimeID} + } + cwEntry, err := h.watchlistSvc.GetContinueWatchingEntry(c.Request.Context(), u.ID, int64(id)) if err == nil && cwEntry.CurrentEpisode.Valid { ep = int(cwEntry.CurrentEpisode.Int64) @@ -267,6 +275,8 @@ func (h *AnimeHandler) HandleAnimeDetails(c *gin.Context) { "Anime": anime, "CurrentPath": fmt.Sprintf("/anime/%d", id), "User": user, + "Status": status, + "WatchlistIDs": watchlistIDs, "ContinueWatchingEp": ep, "ContinueWatchingTime": cwSeconds, }) diff --git a/internal/domain/watchlist.go b/internal/domain/watchlist.go index c7d0b17..419604f 100644 --- a/internal/domain/watchlist.go +++ b/internal/domain/watchlist.go @@ -12,6 +12,7 @@ type WatchlistService interface { UpdateEntry(ctx context.Context, userID string, animeID int64, status string) error RemoveEntry(ctx context.Context, userID string, animeID int64) error GetWatchlist(ctx context.Context, userID string) ([]UserWatchListRow, error) + GetWatchListEntry(ctx context.Context, userID string, animeID int64) (WatchlistEntry, error) GetContinueWatchingEntry(ctx context.Context, userID string, animeID int64) (db.ContinueWatchingEntry, error) DeleteContinueWatching(ctx context.Context, userID string, animeID int64) error } @@ -22,6 +23,7 @@ type WatchlistRepository interface { UpsertWatchListEntry(ctx context.Context, arg db.UpsertWatchListEntryParams) (db.WatchListEntry, error) DeleteWatchListEntry(ctx context.Context, arg db.DeleteWatchListEntryParams) error GetUserWatchList(ctx context.Context, userID string) ([]db.GetUserWatchListRow, error) + GetWatchListEntry(ctx context.Context, arg db.GetWatchListEntryParams) (db.WatchListEntry, error) GetContinueWatchingEntry(ctx context.Context, arg db.GetContinueWatchingEntryParams) (db.ContinueWatchingEntry, error) DeleteContinueWatchingEntry(ctx context.Context, arg db.DeleteContinueWatchingEntryParams) error SaveWatchProgress(ctx context.Context, arg db.SaveWatchProgressParams) error diff --git a/internal/watchlist/repository/repository.go b/internal/watchlist/repository/repository.go index 8f6b8a1..e286383 100644 --- a/internal/watchlist/repository/repository.go +++ b/internal/watchlist/repository/repository.go @@ -34,6 +34,10 @@ func (r *watchlistRepository) GetUserWatchList(ctx context.Context, userID strin return r.queries.GetUserWatchList(ctx, userID) } +func (r *watchlistRepository) GetWatchListEntry(ctx context.Context, arg db.GetWatchListEntryParams) (db.WatchListEntry, error) { + return r.queries.GetWatchListEntry(ctx, arg) +} + func (r *watchlistRepository) GetContinueWatchingEntry(ctx context.Context, arg db.GetContinueWatchingEntryParams) (db.ContinueWatchingEntry, error) { return r.queries.GetContinueWatchingEntry(ctx, arg) } diff --git a/internal/watchlist/service/service.go b/internal/watchlist/service/service.go index a51403c..c4e46c4 100644 --- a/internal/watchlist/service/service.go +++ b/internal/watchlist/service/service.go @@ -55,6 +55,13 @@ func (s *watchlistService) GetWatchlist(ctx context.Context, userID string) ([]d return s.repo.GetUserWatchList(ctx, userID) } +func (s *watchlistService) GetWatchListEntry(ctx context.Context, userID string, animeID int64) (db.WatchListEntry, error) { + return s.repo.GetWatchListEntry(ctx, db.GetWatchListEntryParams{ + UserID: userID, + AnimeID: animeID, + }) +} + func (s *watchlistService) GetContinueWatchingEntry(ctx context.Context, userID string, animeID int64) (db.ContinueWatchingEntry, error) { return s.repo.GetContinueWatchingEntry(ctx, db.GetContinueWatchingEntryParams{ UserID: userID,