Parent directory

handler.go

2077 bytes
 1package handler
 2
 3import (
 4	"context"
 5	"log/slog"
 6
 7	"github.com/TheEdgeOfRage/ytrssil-api/config"
 8	"github.com/TheEdgeOfRage/ytrssil-api/db"
 9	"github.com/TheEdgeOfRage/ytrssil-api/feedparser"
10	"github.com/TheEdgeOfRage/ytrssil-api/lib/clients/youtube"
11	"github.com/TheEdgeOfRage/ytrssil-api/lib/downloader"
12	"github.com/TheEdgeOfRage/ytrssil-api/models"
13)
14
15type Handler interface {
16	SubscribeToChannel(ctx context.Context, channelID string) (*models.Channel, error)
17	UnsubscribeFromChannel(ctx context.Context, channelID string) error
18	ListChannels(ctx context.Context) ([]models.Channel, error)
19	GetChannelByID(ctx context.Context, channelID string) (*models.Channel, error)
20	ToggleChannelShorts(ctx context.Context, channelID string, enableShorts bool) error
21	GetNewVideos(ctx context.Context, sortDesc bool) ([]models.Video, error)
22	GetWatchedVideos(ctx context.Context, sortDesc bool, page int) ([]models.Video, error)
23	GetVideo(ctx context.Context, videoID string) (*models.Video, error)
24	FetchVideos(ctx context.Context) error
25	MarkVideoAsWatched(ctx context.Context, videoID string) error
26	MarkVideoAsUnwatched(ctx context.Context, videoID string) error
27	SetVideoProgress(ctx context.Context, videoID string, progressTime string) (*models.Video, error)
28	AddCustomVideo(ctx context.Context, videoID string) error
29	DownloadVideo(ctx context.Context, videoID string, resolution string) error
30	ServeVideoFile(ctx context.Context, videoID string) (filePath string, filename string, err error)
31	CleanupRoutine(ctx context.Context)
32}
33
34type handler struct {
35	log           *slog.Logger
36	db            db.DB
37	parser        feedparser.Parser
38	youTubeClient youtube.Client
39	downloader    downloader.Downloader
40	config        config.Config
41}
42
43func New(
44	log *slog.Logger,
45	db db.DB,
46	parser feedparser.Parser,
47	youTubeClient youtube.Client,
48	downloader downloader.Downloader,
49	cfg config.Config,
50) *handler {
51	return &handler{
52		log:           log,
53		db:            db,
54		parser:        parser,
55		youTubeClient: youTubeClient,
56		downloader:    downloader,
57		config:        cfg,
58	}
59}