refactor: extract watchlist map to service, optimize command palette queries
This commit is contained in:
@@ -34,6 +34,18 @@ func (r *watchlistRepository) GetUserWatchList(ctx context.Context, userID strin
|
||||
return r.queries.GetUserWatchList(ctx, userID)
|
||||
}
|
||||
|
||||
func (r *watchlistRepository) GetUserWatchlistAnimeIDs(ctx context.Context, userID string, animeIDs []int64) ([]int64, error) {
|
||||
return r.queries.GetUserWatchlistAnimeIDs(ctx, userID, animeIDs)
|
||||
}
|
||||
|
||||
func (r *watchlistRepository) GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]db.GetUserWatchListRow, error) {
|
||||
return r.queries.GetCommandPaletteWatchlist(ctx, userID, query, limit)
|
||||
}
|
||||
|
||||
func (r *watchlistRepository) GetCommandPaletteContinueWatching(ctx context.Context, userID string, query string, limit int64) ([]db.GetContinueWatchingEntriesRow, error) {
|
||||
return r.queries.GetCommandPaletteContinueWatching(ctx, userID, query, limit)
|
||||
}
|
||||
|
||||
func (r *watchlistRepository) GetWatchListEntry(ctx context.Context, arg db.GetWatchListEntryParams) (db.WatchListEntry, error) {
|
||||
return r.queries.GetWatchListEntry(ctx, arg)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,32 @@ func (s *watchlistService) GetWatchlist(ctx context.Context, userID string) ([]d
|
||||
return s.repo.GetUserWatchList(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *watchlistService) GetWatchlistMap(ctx context.Context, userID string, animeIDs []int64) (map[int]bool, error) {
|
||||
watchlistMap := make(map[int]bool)
|
||||
if userID == "" || len(animeIDs) == 0 {
|
||||
return watchlistMap, nil
|
||||
}
|
||||
|
||||
matches, err := s.repo.GetUserWatchlistAnimeIDs(ctx, userID, animeIDs)
|
||||
if err != nil {
|
||||
return watchlistMap, err
|
||||
}
|
||||
|
||||
for _, animeID := range matches {
|
||||
watchlistMap[int(animeID)] = true
|
||||
}
|
||||
|
||||
return watchlistMap, nil
|
||||
}
|
||||
|
||||
func (s *watchlistService) GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]domain.UserWatchListRow, error) {
|
||||
return s.repo.GetCommandPaletteWatchlist(ctx, userID, query, limit)
|
||||
}
|
||||
|
||||
func (s *watchlistService) GetCommandPaletteContinueWatching(ctx context.Context, userID string, query string, limit int64) ([]db.GetContinueWatchingEntriesRow, error) {
|
||||
return s.repo.GetCommandPaletteContinueWatching(ctx, userID, query, limit)
|
||||
}
|
||||
|
||||
func (s *watchlistService) GetWatchListEntry(ctx context.Context, userID string, animeID int64) (db.WatchListEntry, error) {
|
||||
return s.repo.GetWatchListEntry(ctx, db.GetWatchListEntryParams{
|
||||
UserID: userID,
|
||||
|
||||
Reference in New Issue
Block a user