api/db/db.go

50 lines
2.3 KiB
Go
Raw Permalink Normal View History

2022-10-27 04:04:49 +02:00
package db
import (
"context"
2022-10-29 05:09:52 +02:00
"errors"
2022-10-30 01:08:07 +02:00
"time"
2022-10-27 04:04:49 +02:00
"gitea.theedgeofrage.com/TheEdgeOfRage/ytrssil-api/models"
)
2022-10-29 05:09:52 +02:00
var (
ErrChannelExists = errors.New("channel already exists")
2022-10-30 19:23:40 +01:00
ErrChannelNotFound = errors.New("no channel with that ID found")
2022-10-29 05:09:52 +02:00
ErrAlreadySubscribed = errors.New("already subscribed to channel")
ErrVideoExists = errors.New("video already exists")
2022-10-30 01:08:07 +02:00
ErrUserExists = errors.New("user already exists")
2022-10-29 05:09:52 +02:00
)
2022-10-27 04:04:49 +02:00
// DB represents a database layer for getting video and channel data
type DB interface {
2022-10-30 01:08:07 +02:00
// AuthenticateUser verifies a user's password against a hashed value
AuthenticateUser(ctx context.Context, user models.User) (bool, error)
// CreateUser registers a new user in the database
CreateUser(ctx context.Context, user models.User) error
// DeleteUser registers a new user in the database
DeleteUser(ctx context.Context, username string) error
2022-10-29 05:09:52 +02:00
// CreateChannel starts tracking a new channel and fetch new videos for it
CreateChannel(ctx context.Context, channel models.Channel) error
// ListChannels lists all channels from the database
ListChannels(ctx context.Context) ([]models.Channel, error)
// GetChannelSubscribers lists all channels from the database
GetChannelSubscribers(ctx context.Context, channelID string) ([]string, error)
2022-10-30 19:23:40 +01:00
// SubscribeUserToChannel will start adding new videos from that channel to the user
2022-10-29 05:09:52 +02:00
SubscribeUserToChannel(ctx context.Context, username string, channelID string) error
2022-10-30 19:23:40 +01:00
// SubscribeUserToChannel will stop adding videos from that channel to the user
UnsubscribeUserFromChannel(ctx context.Context, username string, channelID string) error
2022-10-30 01:08:07 +02:00
// GetNewVideos returns a list of unwatched videos from all subscribed channels
GetNewVideos(ctx context.Context, username string) ([]models.Video, error)
// GetWatchedVideos returns a list of all watched videos for a user
GetWatchedVideos(ctx context.Context, username string) ([]models.Video, error)
// AddVideo adds a newly published video to the database
AddVideo(ctx context.Context, video models.Video, channelID string) error
2022-10-29 05:09:52 +02:00
// AddVideoToUser will list the video in the users feed
AddVideoToUser(ctx context.Context, username string, videoID string) error
2022-10-30 01:08:07 +02:00
// SetVideoWatchTime sets or unsets the watch timestamp of a user's video
SetVideoWatchTime(ctx context.Context, username string, videoID string, watchTime *time.Time) error
2022-10-27 04:04:49 +02:00
}