refactor(services): accept optional libraryID for All Libraries support

- dashboard_service.go: Change libraryID parameter from uuid.UUID to
  pgtype.UUID across GetDashboardSections, GetDashboardPreferences,
  and all helper methods. pgtype.UUID{Valid: false} now signals
  "no library filter" (All Libraries), which gets passed through
  to sqlc.narg() in the SQL layer.

- series_service.go: Drop libraryID parameter from GetSeriesBooks
  entirely. Series are not library-specific — all books in a series
  are shown regardless of which library they belong to.
This commit is contained in:
2026-05-18 17:52:24 -04:00
parent e7a4f0f758
commit 6a352a6afb
2 changed files with 29 additions and 34 deletions
+19 -18
View File
@@ -135,7 +135,8 @@ type DashboardSection struct {
func (s *DashboardService) GetDashboardSections(
ctx context.Context,
userID, libraryID uuid.UUID,
userID uuid.UUID,
libraryID pgtype.UUID,
limit int,
collectionOrder []string,
hiddenCollections []string,
@@ -267,36 +268,36 @@ func (s *DashboardService) sortByPriority(sections []DashboardSection) []Dashboa
return sorted
}
func (s *DashboardService) getCollectionItemsByQueryType(ctx context.Context, coll database.Collections, userID, libraryID uuid.UUID, limit int) ([]database.MediaItems, error) {
func (s *DashboardService) getCollectionItemsByQueryType(ctx context.Context, coll database.Collections, userID uuid.UUID, libraryID pgtype.UUID, limit int) ([]database.MediaItems, error) {
switch coll.QueryType.String {
case "continue-reading":
return s.db.GetContinueReadingItems(ctx, database.GetContinueReadingItemsParams{
UserID: pgtype.UUID{Bytes: userID, Valid: true},
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Limit: int32(limit),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
case "recently-added":
return s.db.GetRecentlyAddedItems(ctx, database.GetRecentlyAddedItemsParams{
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Limit: int32(limit),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
case "recently-read":
return s.db.GetRecentlyReadItems(ctx, database.GetRecentlyReadItemsParams{
UserID: pgtype.UUID{Bytes: userID, Valid: true},
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Limit: int32(limit),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
case "not-started":
return s.db.GetNotStartedItems(ctx, database.GetNotStartedItemsParams{
UserID: pgtype.UUID{Bytes: userID, Valid: true},
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Limit: int32(limit),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
case "continue-series":
rows, err := s.db.GetContinueSeriesItems(ctx, database.GetContinueSeriesItemsParams{
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
LibraryID: libraryID,
UserID: pgtype.UUID{Bytes: userID, Valid: true},
Limit: int32(limit),
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
if err != nil {
return nil, err
@@ -311,13 +312,13 @@ func (s *DashboardService) getCollectionItemsByQueryType(ctx context.Context, co
}
}
func (s *DashboardService) getUserCollectionItems(ctx context.Context, coll database.Collections, userID, libraryID uuid.UUID, limit int) ([]database.MediaItems, error) {
func (s *DashboardService) getUserCollectionItems(ctx context.Context, coll database.Collections, userID uuid.UUID, libraryID pgtype.UUID, limit int) ([]database.MediaItems, error) {
collUUID, _ := uuid.FromBytes(coll.ID.Bytes[0:16])
manualItems, err := s.db.GetCollectionItemsForDashboard(ctx, database.GetCollectionItemsForDashboardParams{
CollectionID: pgtype.UUID{Bytes: collUUID, Valid: true},
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Limit: int32(limit),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
if err != nil {
return nil, err
@@ -334,7 +335,7 @@ func (s *DashboardService) getUserCollectionItems(ctx context.Context, coll data
if len(coll.AutoAssignRules) > 0 {
var rules []Rule
if err := json.Unmarshal(coll.AutoAssignRules, &rules); err == nil && len(rules) > 0 {
allLibraryItems, err := s.db.GetLibraryItems(ctx, pgtype.UUID{Bytes: libraryID, Valid: true})
allLibraryItems, err := s.db.GetLibraryItems(ctx, libraryID)
if err == nil {
for _, item := range allLibraryItems {
alreadyInCollection := false
@@ -374,10 +375,10 @@ func (s *DashboardService) getUserCollectionItems(ctx context.Context, coll data
return finalItems, nil
}
func (s *DashboardService) GetDashboardPreferences(ctx context.Context, userID, libraryID uuid.UUID) (database.UserDashboardPreferences, error) {
func (s *DashboardService) GetDashboardPreferences(ctx context.Context, userID uuid.UUID, libraryID pgtype.UUID) (database.UserDashboardPreferences, error) {
return s.db.GetDashboardPreferences(ctx, database.GetDashboardPreferencesParams{
UserID: pgtype.UUID{Bytes: userID, Valid: true},
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
LibraryID: libraryID,
})
}
+10 -16
View File
@@ -5,7 +5,6 @@ import (
"bookhoard/internal/utils"
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
@@ -25,18 +24,16 @@ func NewSeriesService(db *database.Queries) *SeriesService {
return &SeriesService{db: db}
}
func (s *SeriesService) GetSeriesPage(ctx context.Context, libraryID uuid.UUID, limit, offset int) ([]SeriesInfo, int, error) {
libUUID := pgtype.UUID{Bytes: libraryID, Valid: true}
totalCount, err := s.db.GetDistinctSeriesCount(ctx, libUUID)
func (s *SeriesService) GetSeriesPage(ctx context.Context, libraryID pgtype.UUID, limit, offset int) ([]SeriesInfo, int, error) {
totalCount, err := s.db.GetDistinctSeriesCount(ctx, libraryID)
if err != nil {
return nil, 0, err
}
rows, err := s.db.GetDistinctSeries(ctx, database.GetDistinctSeriesParams{
LibraryID: libUUID,
Limit: int32(limit),
Offset: int32(offset),
LibraryID: libraryID,
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
Offset: pgtype.Int4{Int32: int32(offset), Valid: true},
})
if err != nil {
return nil, 0, err
@@ -88,11 +85,11 @@ func (s *SeriesService) GetSeriesPage(ctx context.Context, libraryID uuid.UUID,
return series, int(totalCount), nil
}
func (s *SeriesService) GetSeriesCovers(ctx context.Context, libraryID uuid.UUID, seriesName string, limit int) ([]string, error) {
func (s *SeriesService) GetSeriesCovers(ctx context.Context, libraryID pgtype.UUID, seriesName string, limit int) ([]string, error) {
covers, err := s.db.GetSeriesCovers(ctx, database.GetSeriesCoversParams{
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
LibraryID: libraryID,
Series: pgtype.Text{String: seriesName, Valid: true},
Limit: int32(limit),
Limit: pgtype.Int4{Int32: int32(limit), Valid: true},
})
if err != nil {
return nil, err
@@ -109,11 +106,8 @@ func (s *SeriesService) GetSeriesCovers(ctx context.Context, libraryID uuid.UUID
return paths, nil
}
func (s *SeriesService) GetSeriesBooks(ctx context.Context, libraryID uuid.UUID, seriesName string) ([]database.MediaItems, error) {
return s.db.GetSeriesBooks(ctx, database.GetSeriesBooksParams{
LibraryID: pgtype.UUID{Bytes: libraryID, Valid: true},
Series: pgtype.Text{String: seriesName, Valid: true},
})
func (s *SeriesService) GetSeriesBooks(ctx context.Context, seriesName string) ([]database.MediaItems, error) {
return s.db.GetSeriesBooks(ctx, pgtype.Text{String: seriesName, Valid: true})
}
func continueSeriesRowToMediaItems(row database.GetContinueSeriesItemsRow) database.MediaItems {