lists

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//tygo:emit export type ListResponsePermission = "owner" | "manager" | "editor" | "viewer";
	PermissionOwner = "owner"
)

PermissionOwner is the synthetic permission the list/retrieve handlers return for a list's owner. The persisted share grants are the ListPermission values (viewer/editor/manager); "owner" is computed per request, never stored.

Variables

This section is empty.

Functions

func RegisterRoutes added in v0.1.0

func RegisterRoutes(g *echo.Group, db *bun.DB, authMiddleware *auth.Middleware)

RegisterRoutes registers lists routes on a group the server has already configured with authentication. Lists are user-scoped, so the handlers check the caller's permission on the list rather than a role permission. Reading a list's books also requires books:read, because it returns book data. Sharing needs no users permission: recipients come from the authenticated GET /users/directory.

Types

type AddBooksOptions

type AddBooksOptions struct {
	ListID        int
	BookIDs       []int
	AddedByUserID int
}

type AddBooksPayload

type AddBooksPayload struct {
	BookIDs []int `json:"book_ids" validate:"required,min=1,max=500,dive,min=1"`
}

type CheckVisibilityQuery

type CheckVisibilityQuery struct {
	UserID int `query:"user_id" json:"user_id" validate:"required,min=1" tstype:"number"`
}

type CheckVisibilityResponse added in v0.0.47

type CheckVisibilityResponse struct {
	Visible int `json:"visible"`
	Total   int `json:"total"`
}

CheckVisibilityResponse reports how many of a list's books a target user can see given their library access.

type CreateListOptions

type CreateListOptions struct {
	UserID      int
	Name        string
	Description *string
	IsOrdered   bool
	DefaultSort string
}

type CreateListPayload

type CreateListPayload struct {
	Name        string  `json:"name" validate:"required,min=1,max=200"`
	Description *string `json:"description,omitempty" validate:"omitempty,max=2000" tstype:"string"`
	IsOrdered   bool    `json:"is_ordered"`
	DefaultSort *string `` /* 152-byte string literal not displayed */
}

Payloads for create/update endpoints.

type CreateShareOptions

type CreateShareOptions struct {
	ListID         int
	UserID         int
	Permission     string
	SharedByUserID int
}

type CreateSharePayload

type CreateSharePayload struct {
	UserID     int    `json:"user_id" validate:"required,min=1"`
	Permission string `json:"permission" validate:"required,oneof=viewer editor manager" tstype:"ListPermission"`
}

type ListBooksOptions

type ListBooksOptions struct {
	ListID     int
	LibraryIDs []int // Filter by user's accessible libraries (nil = all)
	// MainFileTypes keeps only books with a main file of one of these types.
	// Empty means no filter.
	MainFileTypes []string
	// Search keeps only books matching this full-text query. Empty means no
	// filter.
	Search string
	Sort   string
	Limit  *int
	Offset *int
	// contains filtered or unexported fields
}

type ListBooksQuery

type ListBooksQuery 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"`
	Sort   *string `` /* 157-byte string literal not displayed */
}

type ListListBooksResponse added in v0.0.47

type ListListBooksResponse struct {
	Items []*models.ListBook `json:"items" tstype:"ListBook[]"`
	Total int                `json:"total"`
}

ListListBooksResponse is the books-in-list envelope. Items are ListBook rows (each carrying its Book) so the frontend can read cover cache keys.

type ListListsOptions

type ListListsOptions struct {
	UserID int // Required - shows owned + shared lists
	Limit  *int
	Offset *int
	// contains filtered or unexported fields
}

type ListListsQuery

type ListListsQuery struct {
	Limit  int `query:"limit" json:"limit,omitempty" default:"50" validate:"min=1,max=100"`
	Offset int `query:"offset" json:"offset,omitempty" validate:"min=0"`
}

Query params for list endpoints.

type ListListsResponse added in v0.0.47

type ListListsResponse struct {
	Items []ListResponse `json:"items"`
	Total int            `json:"total"`
}

ListListsResponse is the list-endpoint envelope.

type ListResponse added in v0.0.47

type ListResponse struct {
	models.List `tstype:",extends"`
	BookCount   int    `json:"book_count"`
	Permission  string `json:"permission" tstype:"ListResponsePermission"`
}

ListResponse is a single list augmented with the requesting user's effective permission and the list's book count. The list route returns it per item and the retrieve route returns it alone. It embeds the List model by value so tygo emits `extends List` and the wire format stays byte-identical.

type ListTemplate added in v0.0.47

type ListTemplate struct {
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	Description string `json:"description"`
	IsOrdered   bool   `json:"is_ordered"`
	DefaultSort string `json:"default_sort" tstype:"ListSort"`
}

ListTemplate is a built-in list template offered by the templates endpoint.

type MoveBookPositionPayload

type MoveBookPositionPayload struct {
	Position int `json:"position" validate:"required,min=1"`
}

type RemoveBooksOptions

type RemoveBooksOptions struct {
	ListID  int
	BookIDs []int
}

type RemoveBooksPayload

type RemoveBooksPayload struct {
	BookIDs []int `json:"book_ids" validate:"required,min=1,max=500,dive,min=1"`
}

type ReorderBooksOptions

type ReorderBooksOptions struct {
	ListID  int
	BookIDs []int // New order - book IDs in desired sequence
}

type ReorderBooksPayload

type ReorderBooksPayload struct {
	BookIDs []int `json:"book_ids" validate:"required,min=1,max=500,dive,min=1"`
}

type RetrieveListOptions

type RetrieveListOptions struct {
	ID *int
}

type Service

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

func NewService

func NewService(db *bun.DB) *Service

func (*Service) AddBooks

func (svc *Service) AddBooks(ctx context.Context, opts AddBooksOptions) error

func (*Service) BookLibraryIDs added in v0.1.0

func (svc *Service) BookLibraryIDs(ctx context.Context, bookIDs []int) (map[int]int, error)

BookLibraryIDs maps each existing book id in bookIDs to its library id. Ids with no book are absent from the map.

func (*Service) CanEdit

func (svc *Service) CanEdit(ctx context.Context, listID, userID int) (bool, error)

CanEdit returns true if the user can add/remove books.

func (*Service) CanManage

func (svc *Service) CanManage(ctx context.Context, listID, userID int) (bool, error)

CanManage returns true if the user can edit metadata and share.

func (*Service) CanView

func (svc *Service) CanView(ctx context.Context, listID, userID int) (bool, error)

CanView returns true if the user can view the list.

func (*Service) CheckBookVisibility

func (svc *Service) CheckBookVisibility(ctx context.Context, listID int, targetUserLibraryIDs []int) (visible, total int, err error)

CheckBookVisibility returns counts of visible/total books for a user.

func (*Service) CreateList

func (svc *Service) CreateList(ctx context.Context, opts CreateListOptions) (*models.List, error)

func (*Service) CreateShare

func (svc *Service) CreateShare(ctx context.Context, opts CreateShareOptions) (*models.ListShare, error)

func (*Service) DeleteList

func (svc *Service) DeleteList(ctx context.Context, listID int) error

func (*Service) DeleteShare

func (svc *Service) DeleteShare(ctx context.Context, shareID int) error

func (*Service) GetBookLists

func (svc *Service) GetBookLists(ctx context.Context, bookID, userID int) ([]*models.List, error)

GetBookLists returns lists that contain a specific book (for the user).

func (*Service) GetListBookCount

func (svc *Service) GetListBookCount(ctx context.Context, listID int, libraryIDs []int) (int, error)

GetListBookCount returns the number of books in a list visible to the user.

func (*Service) HasLists added in v0.2.0

func (svc *Service) HasLists(ctx context.Context, userID int) (bool, error)

HasLists reports whether userID owns or has been shared any list.

func (*Service) HasShare

func (svc *Service) HasShare(ctx context.Context, listID, userID int) (bool, error)

HasShare returns true if the user already has a share for the list.

func (*Service) IsActiveUser added in v0.1.0

func (svc *Service) IsActiveUser(ctx context.Context, userID int) (bool, error)

IsActiveUser reports whether userID names an active user, the only kind a list can be shared with.

func (*Service) IsOwner

func (svc *Service) IsOwner(ctx context.Context, listID, userID int) (bool, error)

IsOwner returns true if the user owns the list.

func (*Service) ListBooks

func (svc *Service) ListBooks(ctx context.Context, opts ListBooksOptions) ([]*models.ListBook, error)

func (*Service) ListBooksWithTotal

func (svc *Service) ListBooksWithTotal(ctx context.Context, opts ListBooksOptions) ([]*models.ListBook, int, error)

func (*Service) ListListsWithTotal

func (svc *Service) ListListsWithTotal(ctx context.Context, opts ListListsOptions) ([]*models.List, int, error)

func (*Service) ListShares

func (svc *Service) ListShares(ctx context.Context, listID int) ([]*models.ListShare, error)

func (*Service) MoveBookToPosition

func (svc *Service) MoveBookToPosition(ctx context.Context, listID, bookID, position int) error

MoveBookToPosition moves a book to a specific position within an ordered list.

func (*Service) RemoveBooks

func (svc *Service) RemoveBooks(ctx context.Context, opts RemoveBooksOptions) error

func (*Service) ReorderBooks

func (svc *Service) ReorderBooks(ctx context.Context, opts ReorderBooksOptions) error

func (*Service) RetrieveList

func (svc *Service) RetrieveList(ctx context.Context, opts RetrieveListOptions) (*models.List, error)

func (*Service) UpdateBookListMemberships

func (svc *Service) UpdateBookListMemberships(ctx context.Context, bookID, userID int, listIDs []int) error

UpdateBookListMemberships replaces which lists a book belongs to. Only modifies lists the user can edit.

func (*Service) UpdateList

func (svc *Service) UpdateList(ctx context.Context, list *models.List, opts UpdateListOptions) error

func (*Service) UpdateShare

func (svc *Service) UpdateShare(ctx context.Context, shareID int, permission string) error

type UpdateBookListsPayload

type UpdateBookListsPayload struct {
	ListIDs []int `json:"list_ids" validate:"dive,min=1"`
}

type UpdateListOptions

type UpdateListOptions struct {
	Columns []string
}

type UpdateListPayload

type UpdateListPayload struct {
	Name        *string `json:"name,omitempty" validate:"omitempty,min=1,max=200" tstype:"string"`
	Description *string `json:"description,omitempty" validate:"omitempty,max=2000" tstype:"string"`
	IsOrdered   *bool   `json:"is_ordered,omitempty" tstype:"boolean"`
	DefaultSort *string `` /* 152-byte string literal not displayed */
}

type UpdateSharePayload

type UpdateSharePayload struct {
	Permission string `json:"permission" validate:"required,oneof=viewer editor manager" tstype:"ListPermission"`
}

Jump to

Keyboard shortcuts

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