diff --git a/api/watchlist/service.go b/api/watchlist/service.go index f2f18fc..9823780 100644 --- a/api/watchlist/service.go +++ b/api/watchlist/service.go @@ -71,6 +71,7 @@ func (s *Service) AddEntry(ctx context.Context, userID string, req AddRequest) e Status: req.Status, CurrentEpisode: sql.NullInt64{Int64: 0, Valid: false}, CurrentTimeSeconds: 0, + UpdatedAt: sql.NullTime{Valid: false}, }) if err != nil { return fmt.Errorf("failed to update watchlist: %w", err) diff --git a/internal/db/queries.sql b/internal/db/queries.sql index 9621725..1391505 100644 --- a/internal/db/queries.sql +++ b/internal/db/queries.sql @@ -31,19 +31,17 @@ SELECT * FROM anime WHERE id = ? LIMIT 1; -- name: UpsertWatchListEntry :one INSERT INTO watch_list_entry (id, user_id, anime_id, status, current_episode, current_time_seconds, updated_at) -VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) +VALUES (?, ?, ?, ?, ?, ?, NULL) ON CONFLICT (user_id, anime_id) DO UPDATE SET status = excluded.status, current_episode = excluded.current_episode, - current_time_seconds = excluded.current_time_seconds, - updated_at = CURRENT_TIMESTAMP + current_time_seconds = excluded.current_time_seconds RETURNING *; -- name: SaveWatchProgress :exec UPDATE watch_list_entry SET current_episode = ?, - current_time_seconds = ?, - updated_at = CURRENT_TIMESTAMP + current_time_seconds = ? WHERE user_id = ? AND anime_id = ?; -- name: UpsertContinueWatchingEntry :one diff --git a/internal/db/queries.sql.go b/internal/db/queries.sql.go index 322a454..40a4711 100644 --- a/internal/db/queries.sql.go +++ b/internal/db/queries.sql.go @@ -687,8 +687,7 @@ func (q *Queries) MarkRelationsSynced(ctx context.Context, id int64) error { const saveWatchProgress = `-- name: SaveWatchProgress :exec UPDATE watch_list_entry SET current_episode = ?, - current_time_seconds = ?, - updated_at = CURRENT_TIMESTAMP + current_time_seconds = ? WHERE user_id = ? AND anime_id = ? ` @@ -847,12 +846,11 @@ func (q *Queries) UpsertContinueWatchingEntry(ctx context.Context, arg UpsertCon const upsertWatchListEntry = `-- name: UpsertWatchListEntry :one INSERT INTO watch_list_entry (id, user_id, anime_id, status, current_episode, current_time_seconds, updated_at) -VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) +VALUES (?, ?, ?, ?, ?, ?, NULL) ON CONFLICT (user_id, anime_id) DO UPDATE SET status = excluded.status, current_episode = excluded.current_episode, - current_time_seconds = excluded.current_time_seconds, - updated_at = CURRENT_TIMESTAMP + current_time_seconds = excluded.current_time_seconds RETURNING id, user_id, anime_id, status, created_at, updated_at, current_episode, last_episode_at, current_time_seconds ` @@ -863,6 +861,7 @@ type UpsertWatchListEntryParams struct { Status string `json:"status"` CurrentEpisode sql.NullInt64 `json:"current_episode"` CurrentTimeSeconds float64 `json:"current_time_seconds"` + UpdatedAt sql.NullTime `json:"updated_at"` } func (q *Queries) UpsertWatchListEntry(ctx context.Context, arg UpsertWatchListEntryParams) (WatchListEntry, error) { @@ -873,6 +872,7 @@ func (q *Queries) UpsertWatchListEntry(ctx context.Context, arg UpsertWatchListE arg.Status, arg.CurrentEpisode, arg.CurrentTimeSeconds, + arg.UpdatedAt, ) var i WatchListEntry err := row.Scan(