feat: add resume links

This commit is contained in:
2026-04-18 18:24:57 +02:00
parent c1ee5df94c
commit 0eb7b27676
4 changed files with 68 additions and 16 deletions

View File

@@ -155,7 +155,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) {
userID := userIDFromRequest(r)
anime, currentStatus, err := h.svc.GetAnimeDetails(r.Context(), id, userID)
anime, currentStatus, nextEpisode, err := h.svc.GetAnimeDetails(r.Context(), id, userID)
if err != nil {
if errors.Is(err, ErrAnimePendingFetch) {
templates.AnimePending(id).Render(r.Context(), w)
@@ -172,7 +172,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) {
return
}
templates.AnimeDetails(anime, currentStatus).Render(r.Context(), w)
templates.AnimeDetails(anime, currentStatus, nextEpisode).Render(r.Context(), w)
}
func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) {

View File

@@ -54,22 +54,23 @@ func (s *Service) GetUpcomingAnime(ctx context.Context, page int) (jikan.TopAnim
return s.jikanClient.GetSeasonsUpcoming(ctx, page)
}
func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (jikan.Anime, string, error) {
func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (jikan.Anime, string, int, error) {
anime, err := s.jikanClient.GetAnimeByID(ctx, id)
if err != nil {
if jikan.IsNotFoundError(err) {
return jikan.Anime{}, "", err
return jikan.Anime{}, "", 1, err
}
s.jikanClient.EnqueueAnimeFetchRetry(ctx, id, err)
if jikan.IsRetryableError(err) {
return jikan.Anime{}, "", ErrAnimePendingFetch
return jikan.Anime{}, "", 1, ErrAnimePendingFetch
}
return jikan.Anime{}, "", fmt.Errorf("failed to fetch anime details: %w", err)
return jikan.Anime{}, "", 1, fmt.Errorf("failed to fetch anime details: %w", err)
}
currentStatus := ""
nextEpisode := 1
if userID != "" {
entry, err := s.db.GetWatchListEntry(ctx, database.GetWatchListEntryParams{
UserID: userID,
@@ -77,10 +78,16 @@ func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (j
})
if err == nil {
currentStatus = entry.Status
if entry.CurrentEpisode.Valid {
value := int(entry.CurrentEpisode.Int64)
if value > 0 {
nextEpisode = value
}
}
}
}
return anime, currentStatus, nil
return anime, currentStatus, nextEpisode, nil
}
func (s *Service) GetRelations(ctx context.Context, id int) ([]jikan.RelationEntry, error) {