feat: replace notifications with continue watching

This commit is contained in:
2026-04-18 23:42:22 +02:00
parent dea66f2f6a
commit ed73400b83
9 changed files with 137 additions and 292 deletions

View File

@@ -314,51 +314,6 @@ func (h *Handler) HandleAPIDiscoverUpcoming(w http.ResponseWriter, r *http.Reque
templates.DiscoverItems(res.Animes, "upcoming", page+1, res.HasNextPage).Render(r.Context(), w)
}
func (h *Handler) HandleNotifications(w http.ResponseWriter, r *http.Request) {
userID := userIDFromRequest(r)
if userID == "" {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
tab := r.URL.Query().Get("tab")
if tab != "sequels" {
tab = "tracking"
}
var watching []templates.WatchingAnimeWithDetails
if tab == "tracking" {
var err error
watching, err = h.svc.GetWatchingAnime(r.Context(), userID)
if err != nil {
log.Printf("watching anime error: %v", err)
http.Error(w, "Failed to fetch watching anime", http.StatusInternalServerError)
return
}
}
templates.Notifications(watching, tab).Render(r.Context(), w)
}
func (h *Handler) HandleNotificationsUpcoming(w http.ResponseWriter, r *http.Request) {
userID := userIDFromRequest(r)
if userID == "" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
upcomingSeasons, err := h.svc.GetUpcomingSeasons(r.Context(), userID)
if err != nil {
log.Printf("upcoming seasons error: %v", err)
http.Error(w, "Failed to fetch upcoming seasons", http.StatusInternalServerError)
return
}
templates.UpcomingSeasonsList(upcomingSeasons).Render(r.Context(), w)
}
func (h *Handler) HandleStudioDetails(w http.ResponseWriter, r *http.Request) {
idStr := r.URL.Path[len("/studios/"):]
id, err := strconv.Atoi(idStr)

View File

@@ -6,7 +6,6 @@ import (
"mal/internal/database"
"mal/internal/jikan"
"mal/internal/templates"
)
type Service struct {
@@ -98,52 +97,6 @@ func (s *Service) GetRecommendations(ctx context.Context, animeID int, limit int
return s.jikanClient.GetRecommendations(ctx, animeID, limit)
}
func (s *Service) GetWatchingAnime(ctx context.Context, userID string) ([]templates.WatchingAnimeWithDetails, error) {
rows, err := s.db.GetWatchingAnime(ctx, userID)
if err != nil {
return nil, fmt.Errorf("failed to get watching anime: %w", err)
}
var result []templates.WatchingAnimeWithDetails
for _, row := range rows {
anime, err := s.jikanClient.GetAnimeByID(ctx, int(row.AnimeID))
if err != nil {
if jikan.IsRetryableError(err) {
s.jikanClient.EnqueueAnimeFetchRetry(ctx, int(row.AnimeID), err)
}
// Instead of skipping, we still append it, but without the extra Jikan details
// This prevents anime from vanishing from the watchlist when Jikan rate limits us.
anime = jikan.Anime{}
}
result = append(result, templates.WatchingAnimeWithDetails{
Entry: row,
Anime: anime,
})
}
return result, nil
}
func (s *Service) GetUpcomingSeasons(ctx context.Context, userID string) ([]database.GetUpcomingSeasonsRow, error) {
rows, err := s.db.GetUpcomingSeasons(ctx, userID)
if err != nil {
return nil, fmt.Errorf("failed to get upcoming seasons: %w", err)
}
// Deduplicate by related anime ID
// Because of the recursive query, multiple prequels can point to the same upcoming season
seen := make(map[int64]bool)
var deduped []database.GetUpcomingSeasonsRow
for _, row := range rows {
if !seen[row.ID] {
seen[row.ID] = true
deduped = append(deduped, row)
}
}
return deduped, nil
}
func (s *Service) GetAnimeByProducer(ctx context.Context, producerID int, page int) (jikan.StudioAnimeResult, error) {
return s.jikanClient.GetAnimeByProducer(ctx, producerID, page)
}