番組登録を追加(登録時の過去回の選択、一時停止・再開・解除、既知の回の記録)

This commit is contained in:
2026-10-03 19:44:57 +09:00
parent 2e82a690b1
commit 787eda79ae
21 changed files with 1257 additions and 24 deletions
+5 -10
View File
@@ -59,6 +59,7 @@ type Subscription struct {
Enabled bool
CreatedAt time.Time
LastCheckedAt *time.Time
JobCount int64
}
const jobColumns = `id, episode_id, series_id, series_title, title, broadcaster_name,
@@ -246,21 +247,15 @@ func (s *Store) EpisodeStatuses(ctx context.Context, ids []string) (map[string]s
return result, rows.Err()
}
// AddSubscription は登録済みシリーズのタイトルと有効状態を変更しない。
func (s *Store) AddSubscription(ctx context.Context, seriesID, title string) (bool, error) {
tag, err := s.pool.Exec(ctx, `INSERT INTO subscriptions (series_id, series_title)
VALUES ($1,$2) ON CONFLICT (series_id) DO NOTHING`, seriesID, title)
return tag.RowsAffected() == 1, err
}
func (s *Store) DeleteSubscription(ctx context.Context, seriesID string) (bool, error) {
tag, err := s.pool.Exec(ctx, `DELETE FROM subscriptions WHERE series_id=$1`, seriesID)
return tag.RowsAffected() == 1, err
}
func (s *Store) ListSubscriptions(ctx context.Context) ([]Subscription, error) {
rows, err := s.pool.Query(ctx, `SELECT series_id, series_title, enabled, created_at, last_checked_at
FROM subscriptions ORDER BY created_at DESC, series_id`)
rows, err := s.pool.Query(ctx, `SELECT s.series_id, s.series_title, s.enabled, s.created_at, s.last_checked_at,
(SELECT count(*) FROM download_jobs j WHERE j.series_id=s.series_id)
FROM subscriptions s ORDER BY s.created_at DESC, s.series_id`)
if err != nil {
return nil, err
}
@@ -268,7 +263,7 @@ func (s *Store) ListSubscriptions(ctx context.Context) ([]Subscription, error) {
var subs []Subscription
for rows.Next() {
var sub Subscription
if err := rows.Scan(&sub.SeriesID, &sub.SeriesTitle, &sub.Enabled, &sub.CreatedAt, &sub.LastCheckedAt); err != nil {
if err := rows.Scan(&sub.SeriesID, &sub.SeriesTitle, &sub.Enabled, &sub.CreatedAt, &sub.LastCheckedAt, &sub.JobCount); err != nil {
return nil, err
}
subs = append(subs, sub)