68 lines
2.3 KiB
Go

package episode
import (
"context"
"errors"
"time"
)
var (
ErrNotFound = errors.New("episode not found")
ErrInvalidStartTime = errors.New("invalid start_time (expected HH:MM:SS)")
ErrInvalidPlayback = errors.New("invalid playback_length (expected HH:MM:SS and > 00:00:00)")
ErrInvalidShowInput = errors.New("invalid show payload")
ErrEmptyIDs = errors.New("ids must not be empty")
)
// Episode represents a single show/episode in the system.
type Episode struct {
Id int `json:"id"`
EpNum int `json:"ep_num"`
EpTitle string `json:"ep_title"`
SeasonName string `json:"season_name"`
StartTime string `json:"start_time"`
PlaybackLength string `json:"playback_length"`
CurrentEp bool `json:"current_ep"`
DateCreated time.Time `json:"date_created"`
}
// ArchiveEpisode represents a row in the current_archive table.
type ArchiveEpisode struct {
Id int `json:"id"`
EpNum int `json:"ep_num"`
EpTitle string `json:"ep_title"`
SeasonName string `json:"season_name"`
StartTime string `json:"start_time"`
PlaybackLength string `json:"playback_length"`
CurrentEp bool `json:"current_ep"`
DateCreated time.Time `json:"date_created"`
DateArchived time.Time `json:"date_archived"`
}
// NewShowInput is the payload needed to create a new show/episode.
type NewShowInput struct {
EpNum int `json:"ep_num"`
EpTitle string `json:"ep_title"`
SeasonName string `json:"season_name"`
StartTime string `json:"start_time"`
PlaybackLength string `json:"playback_length"`
}
// MoveResult describes what happened during an archive move operation.
type MoveResult struct {
MovedIDs []int64
DeletedIDs []int64
SkippedIDs []int64
}
// Repository is the storage port that the application layer depends on.
type Repository interface {
GetCurrent(ctx context.Context) (Episode, error)
SetCurrent(ctx context.Context, id int64, startHHMMSS string) error
Create(ctx context.Context, in NewShowInput) (Episode, error)
MoveToArchive(ctx context.Context, ids []int64) (MoveResult, error)
ListAll(ctx context.Context) ([]Episode, error)
ListArchive(ctx context.Context) ([]ArchiveEpisode, error)
Delete(ctx context.Context, id int64) error
}