refactor: update imports to use new db package
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"mal/integrations/jikan"
|
||||
database "mal/internal/db"
|
||||
"mal/internal/db"
|
||||
"mal/internal/middleware"
|
||||
"mal/templates"
|
||||
)
|
||||
@@ -79,7 +79,7 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) {
|
||||
currentEpID := r.URL.Query().Get("ep")
|
||||
if currentEpID == "" {
|
||||
if user != nil {
|
||||
entry, err := h.svc.db.GetWatchListEntry(r.Context(), database.GetWatchListEntryParams{
|
||||
entry, err := h.svc.db.GetWatchListEntry(r.Context(), db.GetWatchListEntryParams{
|
||||
UserID: user.ID,
|
||||
AnimeID: int64(id),
|
||||
})
|
||||
@@ -269,9 +269,9 @@ func (h *Handler) HandleSaveProgress(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// We fetch the anime info to seed the DB if it's the first time saving progress for this show
|
||||
anime, err := h.jikanClient.GetAnimeByID(r.Context(), int(req.MalID))
|
||||
var seed *database.UpsertAnimeParams
|
||||
var seed *db.UpsertAnimeParams
|
||||
if err == nil {
|
||||
seed = &database.UpsertAnimeParams{
|
||||
seed = &db.UpsertAnimeParams{
|
||||
ID: int64(anime.MalID),
|
||||
TitleOriginal: anime.Title,
|
||||
TitleEnglish: sql.NullString{String: anime.TitleEnglish, Valid: anime.TitleEnglish != ""},
|
||||
@@ -315,9 +315,9 @@ func (h *Handler) HandleCompleteAnime(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Seed anime info if needed
|
||||
anime, err := h.jikanClient.GetAnimeByID(r.Context(), int(req.MalID))
|
||||
var seed *database.UpsertAnimeParams
|
||||
var seed *db.UpsertAnimeParams
|
||||
if err == nil {
|
||||
seed = &database.UpsertAnimeParams{
|
||||
seed = &db.UpsertAnimeParams{
|
||||
ID: int64(anime.MalID),
|
||||
TitleOriginal: anime.Title,
|
||||
TitleEnglish: sql.NullString{String: anime.TitleEnglish, Valid: anime.TitleEnglish != ""},
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
"mal/internal/db"
|
||||
)
|
||||
|
||||
func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64, episode int, timeSeconds float64, animeSeed *database.UpsertAnimeParams) error {
|
||||
func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64, episode int, timeSeconds float64, animeSeed *db.UpsertAnimeParams) error {
|
||||
if strings.TrimSpace(userID) == "" || animeID <= 0 || episode <= 0 {
|
||||
return errors.New("invalid save progress input")
|
||||
}
|
||||
|
||||
txQueries, tx, err := database.BeginTx(ctx, s.sqlDB)
|
||||
txQueries, tx, err := db.BeginTx(ctx, s.sqlDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64
|
||||
}
|
||||
}
|
||||
|
||||
watchListEntry, watchListErr := txQueries.GetWatchListEntry(ctx, database.GetWatchListEntryParams{
|
||||
watchListEntry, watchListErr := txQueries.GetWatchListEntry(ctx, db.GetWatchListEntryParams{
|
||||
UserID: userID,
|
||||
AnimeID: animeID,
|
||||
})
|
||||
@@ -40,7 +40,7 @@ func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64
|
||||
|
||||
isCompleted := watchListErr == nil && watchListEntry.Status == "completed"
|
||||
if !isCompleted {
|
||||
if err := txQueries.SaveWatchProgress(ctx, database.SaveWatchProgressParams{
|
||||
if err := txQueries.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
||||
CurrentEpisode: sql.NullInt64{Int64: int64(episode), Valid: true},
|
||||
CurrentTimeSeconds: timeSeconds,
|
||||
UserID: userID,
|
||||
@@ -55,7 +55,7 @@ func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64
|
||||
durationSeconds = animeSeed.DurationSeconds
|
||||
}
|
||||
|
||||
if _, err := txQueries.UpsertContinueWatchingEntry(ctx, database.UpsertContinueWatchingEntryParams{
|
||||
if _, err := txQueries.UpsertContinueWatchingEntry(ctx, db.UpsertContinueWatchingEntryParams{
|
||||
ID: uuid.New().String(),
|
||||
UserID: userID,
|
||||
AnimeID: animeID,
|
||||
@@ -73,19 +73,19 @@ func (s *Service) SaveProgress(ctx context.Context, userID string, animeID int64
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) CompleteAnime(ctx context.Context, userID string, animeID int64, episode int, animeSeed *database.UpsertAnimeParams) error {
|
||||
func (s *Service) CompleteAnime(ctx context.Context, userID string, animeID int64, episode int, animeSeed *db.UpsertAnimeParams) error {
|
||||
if strings.TrimSpace(userID) == "" || animeID <= 0 || episode <= 0 {
|
||||
return errors.New("invalid complete anime input")
|
||||
}
|
||||
|
||||
txQueries, tx, err := database.BeginTx(ctx, s.sqlDB)
|
||||
txQueries, tx, err := db.BeginTx(ctx, s.sqlDB)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer tx.Rollback()
|
||||
|
||||
watchListEntry, watchListErr := txQueries.GetWatchListEntry(ctx, database.GetWatchListEntryParams{
|
||||
watchListEntry, watchListErr := txQueries.GetWatchListEntry(ctx, db.GetWatchListEntryParams{
|
||||
UserID: userID,
|
||||
AnimeID: animeID,
|
||||
})
|
||||
@@ -102,7 +102,7 @@ func (s *Service) CompleteAnime(ctx context.Context, userID string, animeID int6
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := txQueries.UpsertWatchListEntry(ctx, database.UpsertWatchListEntryParams{
|
||||
if _, err := txQueries.UpsertWatchListEntry(ctx, db.UpsertWatchListEntryParams{
|
||||
ID: uuid.New().String(),
|
||||
UserID: userID,
|
||||
AnimeID: animeID,
|
||||
@@ -113,7 +113,7 @@ func (s *Service) CompleteAnime(ctx context.Context, userID string, animeID int6
|
||||
return fmt.Errorf("failed to mark watchlist as completed: %w", err)
|
||||
}
|
||||
|
||||
if err := txQueries.SaveWatchProgress(ctx, database.SaveWatchProgressParams{
|
||||
if err := txQueries.SaveWatchProgress(ctx, db.SaveWatchProgressParams{
|
||||
CurrentEpisode: sql.NullInt64{Int64: 0, Valid: false},
|
||||
CurrentTimeSeconds: 0,
|
||||
UserID: userID,
|
||||
@@ -123,7 +123,7 @@ func (s *Service) CompleteAnime(ctx context.Context, userID string, animeID int6
|
||||
}
|
||||
}
|
||||
|
||||
if err := txQueries.DeleteContinueWatchingEntry(ctx, database.DeleteContinueWatchingEntryParams{
|
||||
if err := txQueries.DeleteContinueWatchingEntry(ctx, db.DeleteContinueWatchingEntryParams{
|
||||
UserID: userID,
|
||||
AnimeID: animeID,
|
||||
}); err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ type Service struct {
|
||||
allAnimeClient *allAnimeClient
|
||||
httpClient *http.Client
|
||||
sqlDB *sql.DB
|
||||
db database.Querier
|
||||
db db.Querier
|
||||
proxyTokens *proxyTokenSigner
|
||||
proxyHostMu sync.RWMutex
|
||||
proxyHostCache map[string]proxyHostCacheItem
|
||||
@@ -93,7 +93,7 @@ type userPlaybackState struct {
|
||||
StartTimeSeconds float64
|
||||
}
|
||||
|
||||
func NewService(db database.Querier, sqlDB *sql.DB, cfg Config) *Service {
|
||||
func NewService(db db.Querier, sqlDB *sql.DB, cfg Config) *Service {
|
||||
proxyTokens, err := newProxyTokenSigner(cfg.ProxyTokenSecret)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to initialize proxy token signer: %v", err))
|
||||
@@ -215,7 +215,7 @@ func (s *Service) fetchUserPlaybackStateAsync(ctx context.Context, userID string
|
||||
go func() {
|
||||
state := userPlaybackState{}
|
||||
|
||||
entry, err := s.db.GetWatchListEntry(ctx, database.GetWatchListEntryParams{
|
||||
entry, err := s.db.GetWatchListEntry(ctx, db.GetWatchListEntryParams{
|
||||
UserID: userID,
|
||||
AnimeID: int64(malID),
|
||||
})
|
||||
@@ -227,7 +227,7 @@ func (s *Service) fetchUserPlaybackStateAsync(ctx context.Context, userID string
|
||||
}
|
||||
|
||||
if state.StartTimeSeconds <= 0 {
|
||||
continueEntry, continueErr := s.db.GetContinueWatchingEntry(ctx, database.GetContinueWatchingEntryParams{
|
||||
continueEntry, continueErr := s.db.GetContinueWatchingEntry(ctx, db.GetContinueWatchingEntryParams{
|
||||
UserID: userID,
|
||||
AnimeID: int64(malID),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user