Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterRoutes(g *echo.Group, db *bun.DB, authMiddleware *auth.Middleware)
- type AddBooksOptions
- type AddBooksPayload
- type CheckVisibilityQuery
- type CheckVisibilityResponse
- type CopyToToReadResponse
- type CreateListOptions
- type CreateListPayload
- type CreateShareOptions
- type CreateSharePayload
- type DeliverableBooks
- type ListBooksOptions
- type ListBooksQuery
- type ListListBooksResponse
- type ListListsOptions
- type ListListsQuery
- type ListListsResponse
- type ListResponse
- type ListTemplate
- type MoveBookPositionPayload
- type RemoveBooksOptions
- type RemoveBooksPayload
- type ReorderBooksOptions
- type ReorderBooksPayload
- type RetrieveListOptions
- type Service
- func (svc *Service) AddBooks(ctx context.Context, opts AddBooksOptions) error
- func (svc *Service) BookIDs(ctx context.Context, listID int, sort string, readerID int, libraryIDs []int) ([]int, error)
- func (svc *Service) BookLibraryIDs(ctx context.Context, bookIDs []int) (map[int]int, error)
- func (svc *Service) CanEdit(ctx context.Context, listID, userID int) (bool, error)
- func (svc *Service) CanManage(ctx context.Context, listID, userID int) (bool, error)
- func (svc *Service) CanView(ctx context.Context, listID, userID int) (bool, error)
- func (svc *Service) CheckBookVisibility(ctx context.Context, listID int, targetUserLibraryIDs []int) (visible, total int, err error)
- func (svc *Service) ContainsBook(ctx context.Context, listID, bookID int) (bool, error)
- func (svc *Service) CreateList(ctx context.Context, opts CreateListOptions) (*models.List, error)
- func (svc *Service) CreateShare(ctx context.Context, opts CreateShareOptions) (*models.ListShare, error)
- func (svc *Service) DeleteList(ctx context.Context, listID int) error
- func (svc *Service) DeleteShare(ctx context.Context, shareID int) error
- func (svc *Service) GetBookLists(ctx context.Context, bookID, userID int) ([]*models.List, error)
- func (svc *Service) GetListBookCount(ctx context.Context, listID int, libraryIDs []int) (int, error)
- func (svc *Service) HasLists(ctx context.Context, userID int, deliverable *DeliverableBooks) (bool, error)
- func (svc *Service) HasShare(ctx context.Context, listID, userID int) (bool, error)
- func (svc *Service) IsActiveUser(ctx context.Context, userID int) (bool, error)
- func (svc *Service) IsOwner(ctx context.Context, listID, userID int) (bool, error)
- func (svc *Service) ListBooks(ctx context.Context, opts ListBooksOptions) ([]*models.ListBook, error)
- func (svc *Service) ListBooksWithTotal(ctx context.Context, opts ListBooksOptions) ([]*models.ListBook, int, error)
- func (svc *Service) ListListsWithTotal(ctx context.Context, opts ListListsOptions) ([]*models.List, int, error)
- func (svc *Service) ListShares(ctx context.Context, listID int) ([]*models.ListShare, error)
- func (svc *Service) MoveBookToPosition(ctx context.Context, listID, bookID, position int) error
- func (svc *Service) OwnsListNamed(ctx context.Context, userID int, name string) (bool, error)
- func (svc *Service) RemoveBooks(ctx context.Context, opts RemoveBooksOptions) error
- func (svc *Service) ReorderBooks(ctx context.Context, opts ReorderBooksOptions) error
- func (svc *Service) RetrieveList(ctx context.Context, opts RetrieveListOptions) (*models.List, error)
- func (svc *Service) UpdateBookListMemberships(ctx context.Context, bookID, userID int, listIDs []int) error
- func (svc *Service) UpdateList(ctx context.Context, list *models.List, opts UpdateListOptions) error
- func (svc *Service) UpdateShare(ctx context.Context, shareID int, permission string) error
- type UpdateBookListsPayload
- type UpdateListOptions
- type UpdateListPayload
- type UpdateSharePayload
Constants ¶
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 ¶
var ErrListNameTaken = errors.New("the user already has a list with this name")
ErrListNameTaken is returned when a create or rename would give a user two lists with the same name, ignoring case.
Functions ¶
func RegisterRoutes ¶ added in v0.1.0
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, as does copying them to To Read, since the reading routes need it. Sharing needs no users permission: recipients come from the authenticated GET /users/directory.
Types ¶
type AddBooksOptions ¶
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
CheckVisibilityResponse reports how many of a list's books a target user can see given their library access.
type CopyToToReadResponse ¶ added in v0.6.0
type CopyToToReadResponse struct {
Added int `json:"added"`
}
CopyToToReadResponse says how many of a List's Books Copy to To Read added. Books already on To Read, or being read, are skipped.
type CreateListOptions ¶
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 `` /* 251-byte string literal not displayed */
}
Payloads for create/update endpoints.
type CreateShareOptions ¶
type CreateShareOptions struct {
}
type CreateSharePayload ¶
type CreateSharePayload struct {
}
type DeliverableBooks ¶ added in v0.5.0
DeliverableBooks matches the books a reader can receive: books in LibraryIDs (nil means every library) with a main file of one of MainFileTypes (an empty list matches no book).
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.
// Nil means no filter; an empty list matches no book.
MainFileTypes []string
// Search keeps only books matching this full-text query. Empty means no
// filter.
Search string
// ReaderID is the user whose reading data Reading and the rating and
// finish date sorts read. Without it, those are ignored.
ReaderID *int
Reading reading.Filter
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 `` /* 256-byte string literal not displayed */
// Only Books whose caller's Reading Status is any of these; "none"
// matches Books with no status.
ReadingStatuses []string `` /* 181-byte string literal not displayed */
// Only Books the caller rated in this range of stars, both ends included.
RatingMin *float64 `query:"rating_min" json:"rating_min,omitempty" validate:"omitempty,min=0.25,max=5" tstype:"number"`
RatingMax *float64 `query:"rating_max" json:"rating_max,omitempty" validate:"omitempty,min=0.25,max=5" tstype:"number"`
}
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
// ListID, when set, keeps only that list.
ListID *int
Limit *int
Offset *int
// Deliverable, when set, keeps only lists with a book it matches.
Deliverable *DeliverableBooks
// 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 RemoveBooksPayload ¶
type RemoveBooksPayload struct {
BookIDs []int `json:"book_ids" validate:"required,min=1,max=500,dive,min=1"`
}
type ReorderBooksOptions ¶
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 (*Service) AddBooks ¶
func (svc *Service) AddBooks(ctx context.Context, opts AddBooksOptions) error
func (*Service) BookIDs ¶ added in v0.6.0
func (svc *Service) BookIDs(ctx context.Context, listID int, sort string, readerID int, libraryIDs []int) ([]int, error)
BookIDs returns the ids of listID's Books in sort's order, as readerID sees it, limited to libraryIDs when it isn't nil.
func (*Service) BookLibraryIDs ¶ added in v0.1.0
BookLibraryIDs maps each existing book id in bookIDs to its library id. Ids with no book are absent from the map.
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) ContainsBook ¶ added in v0.5.0
ContainsBook reports whether bookID is on listID.
func (*Service) CreateList ¶
func (*Service) CreateShare ¶
func (*Service) DeleteShare ¶
func (*Service) GetBookLists ¶
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, deliverable *DeliverableBooks) (bool, error)
HasLists reports whether userID owns or has been shared a list, with a book deliverable matches when it is non-nil.
func (*Service) IsActiveUser ¶ added in v0.1.0
IsActiveUser reports whether userID names an active user, the only kind a list can be shared with.
func (*Service) ListBooksWithTotal ¶
func (*Service) ListListsWithTotal ¶
func (*Service) ListShares ¶
func (*Service) MoveBookToPosition ¶
MoveBookToPosition moves a book to a specific position within an ordered list.
func (*Service) OwnsListNamed ¶ added in v0.7.0
OwnsListNamed reports whether userID owns a list called name, ignoring case the way the unique name index does.
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 (*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 ¶
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 `` /* 251-byte string literal not displayed */
}
type UpdateSharePayload ¶
type UpdateSharePayload struct {
}