genres

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

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 ListGenresOptions struct {
	Limit      *int
	Offset     *int
	LibraryID  *int
	LibraryIDs []int // Filter by multiple library IDs (for access control)
	Search     *string
	Sort       []sortspec.SortLevel // Defaults to name ascending
	// contains filtered or unexported fields
}

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 RetrieveGenreOptions struct {
	ID        *int
	Name      *string
	LibraryID *int
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(db *bun.DB) *Service

func (*Service) CleanupOrphanedGenres

func (svc *Service) CleanupOrphanedGenres(ctx context.Context) ([]int, error)

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 (svc *Service) CreateGenre(ctx context.Context, genre *models.Genre) error

func (*Service) DeleteGenre

func (svc *Service) DeleteGenre(ctx context.Context, genreID int) ([]int, error)

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

func (svc *Service) GetBookCount(ctx context.Context, genreID int) (int, error)

GetBookCount returns the count of books with this genre.

func (*Service) ListGenres

func (svc *Service) ListGenres(ctx context.Context, opts ListGenresOptions) ([]*models.Genre, error)

func (*Service) ListGenresWithTotal

func (svc *Service) ListGenresWithTotal(ctx context.Context, opts ListGenresOptions) ([]*models.Genre, int, error)

func (*Service) MergeGenres

func (svc *Service) MergeGenres(ctx context.Context, targetID, sourceID int) error

MergeGenres merges sourceGenre into targetGenre (moves all associations, deletes source). A Genre cannot be merged into itself.

func (*Service) RetrieveGenre

func (svc *Service) RetrieveGenre(ctx context.Context, opts RetrieveGenreOptions) (*models.Genre, error)

func (*Service) UpdateGenre

func (svc *Service) UpdateGenre(ctx context.Context, genre *models.Genre, opts UpdateGenreOptions) error

type UpdateGenreOptions

type UpdateGenreOptions struct {
	Columns []string
}

type UpdateGenrePayload

type UpdateGenrePayload struct {
	Name    *string  `json:"name,omitempty" validate:"omitempty,min=1,max=300"`
	Aliases []string `json:"aliases,omitempty" validate:"omitempty,dive,min=1,max=300"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址