Documentation
¶
Index ¶
- func RegisterRoutes(g *echo.Group, db *bun.DB, authMiddleware *auth.Middleware, ...)
- type GenreListItem
- type GenreResponse
- type ListGenresOptions
- type ListGenresQuery
- type ListGenresResponse
- type MergeGenresPayload
- type RetrieveGenreOptions
- type Service
- func (svc *Service) CleanupOrphanedGenres(ctx context.Context) ([]int, error)
- func (svc *Service) CreateGenre(ctx context.Context, genre *models.Genre) error
- func (svc *Service) DeleteGenre(ctx context.Context, genreID int) ([]int, error)
- func (svc *Service) FindOrCreateGenre(ctx context.Context, name string, libraryID int) (*models.Genre, error)
- func (svc *Service) GetBookCount(ctx context.Context, genreID int) (int, error)
- func (svc *Service) ListGenres(ctx context.Context, opts ListGenresOptions) ([]*models.Genre, error)
- func (svc *Service) ListGenresWithTotal(ctx context.Context, opts ListGenresOptions) ([]*models.Genre, int, error)
- func (svc *Service) MergeGenres(ctx context.Context, targetID, sourceID int) error
- func (svc *Service) RetrieveGenre(ctx context.Context, opts RetrieveGenreOptions) (*models.Genre, error)
- func (svc *Service) UpdateGenre(ctx context.Context, genre *models.Genre, opts UpdateGenreOptions) error
- type UpdateGenreOptions
- type UpdateGenrePayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterRoutes ¶ added in v0.1.0
func RegisterRoutes(g *echo.Group, db *bun.DB, authMiddleware *auth.Middleware, reviewRecomputer review.BookReviewRecomputer)
RegisterRoutes registers genre routes on a group the server has already configured with authentication and the resource's read permission. reviewRecomputer is required; pass a books service with app settings attached, or the delete handler's review recompute does nothing.
Types ¶
type GenreListItem ¶ added in v0.5.0
type GenreListItem struct {
GenreResponse `tstype:",extends"`
PreviewBooks []bookpreviews.PreviewBook `json:"preview_books" tstype:"PreviewBook[]"`
}
GenreListItem is a genre row of the list endpoint: the single-genre response plus the covers the list shows for it.
type GenreResponse ¶ added in v0.0.47
type GenreResponse struct {
models.Genre `tstype:",extends"`
BookCount int `json:"book_count"`
Aliases []string `json:"aliases"`
}
GenreResponse is the single-genre API response. It embeds the Genre model by value (so tygo emits `extends Genre`) and reshapes the aliases relation into a flat []string. BookCount and Aliases shadow the embedded model's same-json-tag fields, so the wire format is byte-identical to the previous anonymous struct.
type ListGenresOptions ¶
type ListGenresQuery ¶
type ListGenresQuery struct {
Limit int `query:"limit" json:"limit,omitempty" default:"24" validate:"min=1,max=100"`
Offset int `query:"offset" json:"offset,omitempty" validate:"min=0"`
LibraryID *int `query:"library_id" json:"library_id,omitempty" validate:"omitempty,min=1" tstype:"number"`
Search *string `query:"search" json:"search,omitempty" validate:"omitempty,max=100" tstype:"string"`
Sort string `query:"sort" json:"sort,omitempty" validate:"omitempty,max=200"`
}
type ListGenresResponse ¶ added in v0.0.47
type ListGenresResponse struct {
Items []GenreListItem `json:"items"`
Total int `json:"total"`
}
ListGenresResponse is the list-endpoint envelope.
type MergeGenresPayload ¶
type MergeGenresPayload struct {
SourceID int `json:"source_id" validate:"required,min=1"`
}
type RetrieveGenreOptions ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) CleanupOrphanedGenres ¶
CleanupOrphanedGenres deletes genres with no book associations and returns the IDs of deleted genres. Callers must pass the returned IDs to searchService.DeleteFromGenreIndex to keep genres_fts in sync — genres_fts is a virtual FTS5 table not tied to genres via foreign keys, so it is not cleaned up automatically.
func (*Service) CreateGenre ¶
func (*Service) DeleteGenre ¶
DeleteGenre deletes a genre and all book associations. Every book that carried the genre gets genre_source = manual first, whatever the prior source was and even when other genres remain, the same state the Edit form leaves after removing it. The delete is a deliberate user action, so an ordinary Scan must not bring the genre back from a sidecar or the file, while Refresh all metadata and Reset to file metadata still may (ADR 0006). Only this service path is supported.
Returns the IDs of the books that carried the genre, so the caller can recompute their review state after the transaction commits.
func (*Service) FindOrCreateGenre ¶
func (svc *Service) FindOrCreateGenre(ctx context.Context, name string, libraryID int) (*models.Genre, error)
FindOrCreateGenre finds an existing genre or creates a new one (case-insensitive match).
func (*Service) GetBookCount ¶
GetBookCount returns the count of books with this genre.
func (*Service) ListGenres ¶
func (*Service) ListGenresWithTotal ¶
func (*Service) MergeGenres ¶
MergeGenres merges sourceGenre into targetGenre (moves all associations, deletes source). A Genre cannot be merged into itself.
func (*Service) RetrieveGenre ¶
func (*Service) UpdateGenre ¶
type UpdateGenreOptions ¶
type UpdateGenreOptions struct {
Columns []string
}