fix: preserve watchlist progress on complete and status update
This commit is contained in:
@@ -215,6 +215,8 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
watchlistIDs = []int64{entry.AnimeID}
|
watchlistIDs = []int64{entry.AnimeID}
|
||||||
if entry.CurrentEpisode.Valid && strconv.FormatInt(entry.CurrentEpisode.Int64, 10) == episode {
|
if entry.CurrentEpisode.Valid && strconv.FormatInt(entry.CurrentEpisode.Int64, 10) == episode {
|
||||||
startTime = entry.CurrentTimeSeconds
|
startTime = entry.CurrentTimeSeconds
|
||||||
|
} else if anime.Episodes > 0 && episode == strconv.Itoa(anime.Episodes) && entry.CurrentEpisode.Valid && entry.CurrentEpisode.Int64 == int64(anime.Episodes) {
|
||||||
|
startTime = entry.CurrentTimeSeconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,8 +226,12 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: int64(animeID),
|
AnimeID: int64(animeID),
|
||||||
})
|
})
|
||||||
if err == nil && cwEntry.CurrentEpisode.Valid && strconv.FormatInt(cwEntry.CurrentEpisode.Int64, 10) == episode {
|
if err == nil {
|
||||||
startTime = cwEntry.CurrentTimeSeconds
|
if cwEntry.CurrentEpisode.Valid && strconv.FormatInt(cwEntry.CurrentEpisode.Int64, 10) == episode {
|
||||||
|
startTime = cwEntry.CurrentTimeSeconds
|
||||||
|
} else if anime.Episodes > 0 && episode == strconv.Itoa(anime.Episodes) && cwEntry.CurrentEpisode.Valid && cwEntry.CurrentEpisode.Int64 == int64(anime.Episodes) {
|
||||||
|
startTime = cwEntry.CurrentTimeSeconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,6 +292,7 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
return modes
|
return modes
|
||||||
}(),
|
}(),
|
||||||
Segments: segments,
|
Segments: segments,
|
||||||
|
Airing: anime.Airing,
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain.WatchPageData{
|
return domain.WatchPageData{
|
||||||
@@ -311,26 +318,15 @@ func (s *playbackService) CompleteAnime(ctx context.Context, userID string, anim
|
|||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
Status: "completed",
|
Status: "completed",
|
||||||
CurrentEpisode: sql.NullInt64{Valid: false},
|
CurrentEpisode: entry.CurrentEpisode,
|
||||||
CurrentTimeSeconds: 0,
|
CurrentTimeSeconds: entry.CurrentTimeSeconds,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo.DeleteContinueWatchingEntry(txCtx, db.DeleteContinueWatchingEntryParams{
|
return nil
|
||||||
UserID: userID,
|
|
||||||
AnimeID: animeID,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return repo.SaveWatchProgress(txCtx, db.SaveWatchProgressParams{
|
|
||||||
UserID: userID,
|
|
||||||
AnimeID: animeID,
|
|
||||||
CurrentEpisode: sql.NullInt64{Valid: false},
|
|
||||||
CurrentTimeSeconds: 0,
|
|
||||||
})
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -385,6 +381,12 @@ func (s *playbackService) SaveProgress(ctx context.Context, userID string, anime
|
|||||||
ResourceID: strconv.FormatInt(animeID, 10),
|
ResourceID: strconv.FormatInt(animeID, 10),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
observability.Info("watch_progress_saved", "playback", "", map[string]any{
|
||||||
|
"anime_id": animeID,
|
||||||
|
"episode": episode,
|
||||||
|
"time_seconds": timeSeconds,
|
||||||
|
"user_id": userID,
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,11 +41,18 @@ func (s *watchlistService) UpdateEntry(ctx context.Context, userID string, anime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = repo.UpsertWatchListEntry(txCtx, db.UpsertWatchListEntryParams{
|
existing, _ := repo.GetWatchListEntry(txCtx, db.GetWatchListEntryParams{
|
||||||
ID: uuid.New().String(),
|
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
Status: status,
|
})
|
||||||
|
|
||||||
|
_, err = repo.UpsertWatchListEntry(txCtx, db.UpsertWatchListEntryParams{
|
||||||
|
ID: uuid.New().String(),
|
||||||
|
UserID: userID,
|
||||||
|
AnimeID: animeID,
|
||||||
|
Status: status,
|
||||||
|
CurrentEpisode: existing.CurrentEpisode,
|
||||||
|
CurrentTimeSeconds: existing.CurrentTimeSeconds,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user