bestiary

package
v0.0.0-...-95891f2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bestiary provides the Community Bestiary plugin for sharing homebrew creatures across a Chronicle instance. Users can publish, browse, rate, favorite, and import creature statblocks. Instance admins can moderate content.

This file embeds the plugin's SQL migration files so they are available in the compiled binary regardless of the runtime working directory.

Index

Constants

View Source
const (
	// VisibilityDraft means only the creator can see the publication.
	VisibilityDraft = "draft"
	// VisibilityPublished means the publication is visible in search/browse.
	VisibilityPublished = "published"
	// VisibilityUnlisted means accessible by direct link only, not in search.
	VisibilityUnlisted = "unlisted"
	// VisibilityArchived means removed from search by creator or admin.
	VisibilityArchived = "archived"
	// VisibilityFlagged means auto-hidden after 3+ user flags, pending moderation.
	VisibilityFlagged = "flagged"
)

Variables

View Source
var MigrationsFS embed.FS

MigrationsFS contains the embedded SQL migration files for the bestiary plugin.

ValidVisibilities is the set of allowed visibility values.

Functions

func RegisterAdminRoutes

func RegisterAdminRoutes(e *echo.Echo, h *Handler, authSvc auth.AuthService)

RegisterAdminRoutes sets up admin/moderation routes for the bestiary. These require site admin privileges and live under /admin/bestiary/*.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, h *Handler, authSvc auth.AuthService)

RegisterRoutes sets up all bestiary-related routes. Bestiary routes are instance-scoped (not campaign-scoped) and require authentication. All endpoints live under /bestiary/*.

func UserRateLimit

func UserRateLimit(maxRequests int, window time.Duration) echo.MiddlewareFunc

UserRateLimit returns middleware that limits requests per authenticated user to maxRequests within the given window duration. Returns 429 with a Retry-After header when exceeded. Unauthenticated requests are rejected.

Types

type BestiaryRepository

type BestiaryRepository interface {
	// Publication CRUD.
	CreatePublication(ctx context.Context, p *Publication) error
	GetByID(ctx context.Context, id string) (*Publication, error)
	GetBySlug(ctx context.Context, slug string) (*Publication, error)
	UpdatePublication(ctx context.Context, p *Publication) error
	ArchivePublication(ctx context.Context, id string) error
	UpdateVisibility(ctx context.Context, id, visibility string) error
	// ApplyModeration sets the visibility a moderator action produced, the
	// state to return to later (nil clears it) and, when resetFlags is set,
	// zeroes flagged_count so a restored publication needs a fresh round of
	// flags to be hidden again.
	ApplyModeration(ctx context.Context, id, visibility string, prior *string, resetFlags bool) error
	// ReconcileEscapedText unescapes name, description and flavor text that the
	// old write path HTML-escaped, once per row. Returns rows changed.
	ReconcileEscapedText(ctx context.Context) (int, error)

	// Listing.
	ListPublished(ctx context.Context, page, perPage int) ([]Publication, int, error)
	ListByCreator(ctx context.Context, creatorID string, includeAll bool, page, perPage int) ([]Publication, int, error)

	// Search & feeds.
	SearchPublications(ctx context.Context, filters SearchFilters) ([]Publication, int, error)
	ListNewest(ctx context.Context, page, perPage int) ([]Publication, int, error)
	ListTopRated(ctx context.Context, page, perPage int) ([]Publication, int, error)
	ListMostImported(ctx context.Context, page, perPage int) ([]Publication, int, error)

	// Creator stats.
	GetCreatorStats(ctx context.Context, creatorID string) (*CreatorStats, error)

	// Ratings.
	CreateRating(ctx context.Context, r *Rating) error
	UpdateRating(ctx context.Context, r *Rating) error
	DeleteRating(ctx context.Context, userID, publicationID string) error
	GetRating(ctx context.Context, userID, publicationID string) (*Rating, error)
	ListReviews(ctx context.Context, publicationID string, page, perPage int) ([]Rating, int, error)
	// AdjustRatingAggregates atomically updates rating_sum and rating_count on a publication.
	AdjustRatingAggregates(ctx context.Context, publicationID string, sumDelta, countDelta int) error

	// Favorites.
	AddFavorite(ctx context.Context, userID, publicationID string) error
	RemoveFavorite(ctx context.Context, userID, publicationID string) error
	IsFavorited(ctx context.Context, userID, publicationID string) (bool, error)
	ListFavorites(ctx context.Context, userID string, page, perPage int) ([]Publication, int, error)
	// AdjustFavoriteCount atomically updates the favorites counter on a publication.
	AdjustFavoriteCount(ctx context.Context, publicationID string, delta int) error

	// Imports.
	CreateImport(ctx context.Context, imp *Import) error
	// GetImport returns the import record for a publication in a campaign, or
	// nil when there is none.
	GetImport(ctx context.Context, publicationID, campaignID string) (*Import, error)
	// DeleteImport removes the record, so a creature whose page is gone can be
	// imported again.
	DeleteImport(ctx context.Context, publicationID, campaignID string) error
	ImportExists(ctx context.Context, publicationID, campaignID string) (bool, error)
	IncrementDownloads(ctx context.Context, publicationID string) error

	// Transactional rating operations (row-locked to prevent race conditions).
	RatePublication(ctx context.Context, publicationID, userID string, rating int, reviewText *string) (isNew bool, err error)
	RemoveRatingWithAggregates(ctx context.Context, publicationID, userID string) error

	// Transactional favorite operations (row-locked to prevent race conditions).
	ToggleFavoriteWithCount(ctx context.Context, publicationID, userID string) (favorited bool, err error)
	RemoveFavoriteWithCount(ctx context.Context, publicationID, userID string) error

	// Flagging (transactional with per-user deduplication).
	FlagPublicationAtomic(ctx context.Context, userID, publicationID string, reason *string, threshold int) error
	FlagExists(ctx context.Context, userID, publicationID string) (bool, error)
	IncrementFlaggedCount(ctx context.Context, publicationID string) (newCount int, err error)
	AutoFlagIfThreshold(ctx context.Context, publicationID string, threshold int) error

	// Moderation.
	ListFlagged(ctx context.Context, page, perPage int) ([]Publication, int, error)
	CreateModerationEntry(ctx context.Context, entry *ModerationLogEntry) error
	GetModerationLog(ctx context.Context, publicationID string) ([]ModerationLogEntry, error)
	GetBestiaryStats(ctx context.Context) (*BestiaryStats, error)
	SetReviewedBy(ctx context.Context, publicationID, moderatorID string) error

	// Slug uniqueness.
	SlugExists(ctx context.Context, slug string) (bool, error)
}

BestiaryRepository defines persistence operations for bestiary publications.

func NewBestiaryRepository

func NewBestiaryRepository(db *sql.DB) BestiaryRepository

NewBestiaryRepository creates a new MariaDB-backed bestiary repository.

type BestiaryService

type BestiaryService interface {
	// Publish creates a new publication from validated input.
	Publish(ctx context.Context, creatorID string, input CreatePublicationInput) (*Publication, error)
	// GetBySlug returns a publication by its URL slug.
	GetBySlug(ctx context.Context, slug string) (*Publication, error)
	// ViewBySlug returns a publication by slug as userID may see it: hidden
	// ones are not found for anyone but the creator, and ids from the creator's
	// own campaign and moderation details are removed for everyone else.
	ViewBySlug(ctx context.Context, userID, slug string) (*Publication, error)
	// GetByID returns a publication by its UUID.
	GetByID(ctx context.Context, id string) (*Publication, error)
	// Update modifies an existing publication (creator only).
	Update(ctx context.Context, userID, publicationID string, input UpdatePublicationInput) (*Publication, error)
	// Archive soft-deletes a publication (creator only).
	Archive(ctx context.Context, userID, publicationID string) error
	// ChangeVisibility changes the visibility state (creator only).
	ChangeVisibility(ctx context.Context, userID, publicationID string, visibility string) error
	// ListPublished returns paginated published publications.
	ListPublished(ctx context.Context, page, perPage int) (*PublicationListResult, error)
	// ListMyCreations returns paginated publications by the requesting user.
	ListMyCreations(ctx context.Context, userID string, page, perPage int) (*PublicationListResult, error)

	// Search performs filtered, paginated search across published publications.
	Search(ctx context.Context, filters SearchFilters) (*PublicationListResult, error)
	// ListNewest returns the most recently published publications.
	ListNewest(ctx context.Context, page, perPage int) (*PublicationListResult, error)
	// ListTopRated returns publications with the highest average rating.
	ListTopRated(ctx context.Context, page, perPage int) (*PublicationListResult, error)
	// ListMostImported returns publications with the most downloads.
	ListMostImported(ctx context.Context, page, perPage int) (*PublicationListResult, error)
	// GetCreatorProfile returns a creator's public profile with stats.
	GetCreatorProfile(ctx context.Context, userID string) (*CreatorProfile, error)

	// Rate creates or updates a rating on a publication.
	Rate(ctx context.Context, userID, publicationID string, rating int, reviewText *string) error
	// RemoveRating removes a user's rating on a publication.
	RemoveRating(ctx context.Context, userID, publicationID string) error
	// ListReviews returns paginated reviews for a publication the user may see.
	ListReviews(ctx context.Context, userID, publicationID string, page, perPage int) (*ReviewListResult, error)
	// ToggleFavorite adds or removes a favorite, returning the new state.
	ToggleFavorite(ctx context.Context, userID, publicationID string) (favorited bool, err error)
	// RemoveFavorite removes a user's favorite on a publication.
	RemoveFavorite(ctx context.Context, userID, publicationID string) error
	// ListFavorites returns paginated publications favorited by a user.
	ListFavorites(ctx context.Context, userID string, page, perPage int) (*PublicationListResult, error)

	// Import imports a publication's creature into a campaign.
	Import(ctx context.Context, userID, publicationID, campaignID string) (*ImportResult, error)
	// Fork imports a publication as an editable copy into a campaign.
	Fork(ctx context.Context, userID, publicationID, campaignID string) (*ImportResult, error)
	// Flag flags a publication for moderation.
	Flag(ctx context.Context, userID, publicationID string, reason *string) error

	// Moderate performs an admin moderation action on a publication.
	Moderate(ctx context.Context, moderatorID, publicationID, action string, reason *string) error
	// GetModerationLog returns the moderation audit trail for a publication.
	GetModerationLog(ctx context.Context, publicationID string) ([]ModerationLogEntry, error)
	// ListFlagged returns paginated flagged publications for admin review.
	ListFlagged(ctx context.Context, page, perPage int) (*PublicationListResult, error)
	// GetStats returns aggregate bestiary statistics for admin dashboard.
	GetStats(ctx context.Context) (*BestiaryStats, error)

	// SetUserFetcher sets the cross-plugin interface for user lookups.
	SetUserFetcher(uf UserFetcher)
	// SetEntityCreator sets the cross-plugin interface for entity creation.
	SetEntityCreator(ec EntityCreator)
	// SetCampaignRoleChecker sets the cross-plugin interface for campaign role checks.
	SetCampaignRoleChecker(rc CampaignRoleChecker)
	// SetCampaignSystemFetcher sets the cross-plugin interface for resolving
	// a campaign's selected game system slug.
	SetCampaignSystemFetcher(csf CampaignSystemFetcher)
}

BestiaryService defines business logic for the community bestiary.

func NewBestiaryService

func NewBestiaryService(repo BestiaryRepository) BestiaryService

NewBestiaryService creates a BestiaryService backed by the given repository.

type BestiaryStats

type BestiaryStats struct {
	TotalPublications int `json:"total_publications"`
	PublishedCount    int `json:"published_count"`
	FlaggedCount      int `json:"flagged_count"`
	TotalRatings      int `json:"total_ratings"`
	TotalImports      int `json:"total_imports"`
	TotalCreators     int `json:"total_creators"`
}

BestiaryStats holds aggregate statistics for the admin dashboard.

type CampaignRoleChecker

type CampaignRoleChecker interface {
	HasMinRole(ctx context.Context, campaignID, userID string, minRole int) (bool, error)
}

CampaignRoleChecker verifies a user's role in a campaign. Implemented via an adapter wrapping the campaigns service in routes.go.

type CampaignSystemFetcher

type CampaignSystemFetcher interface {
	GetCampaignSystemID(ctx context.Context, campaignID string) (string, error)
}

CampaignSystemFetcher returns the game system slug a campaign has selected in its settings (e.g. "dnd5e", "drawsteel"). Returns an empty string if the campaign has no system selected. Used by Publish to tag a publication with the source campaign's system rather than guessing a default. Implemented via an adapter wrapping the campaigns service in routes.go.

type ChangeVisibilityInput

type ChangeVisibilityInput struct {
	Visibility string `json:"visibility"`
}

ChangeVisibilityInput is the validated input for changing publication visibility.

type CreatePublicationInput

type CreatePublicationInput struct {
	SourceEntityID   *string         `json:"source_entity_id,omitempty"`
	SourceCampaignID *string         `json:"source_campaign_id,omitempty"`
	SystemID         string          `json:"system_id"`
	Name             string          `json:"name"`
	Description      *string         `json:"description,omitempty"`
	FlavorText       *string         `json:"flavor_text,omitempty"`
	Tags             json.RawMessage `json:"tags,omitempty"`
	StatblockJSON    json.RawMessage `json:"statblock_json"`
	Visibility       string          `json:"visibility"`
}

CreatePublicationInput is the validated input for publishing a creature.

type CreatorProfile

type CreatorProfile struct {
	UserID      string       `json:"user_id"`
	DisplayName string       `json:"display_name"`
	AvatarURL   string       `json:"avatar_url,omitempty"`
	Stats       CreatorStats `json:"stats"`
}

CreatorProfile is the public profile of a bestiary creator, combining user info (fetched via UserFetcher) with aggregated publication stats.

type CreatorStats

type CreatorStats struct {
	PublicationCount int     `json:"publication_count"`
	TotalDownloads   int     `json:"total_downloads"`
	TotalRatings     int     `json:"total_ratings"`
	AverageRating    float64 `json:"average_rating"`
}

CreatorStats holds aggregated statistics for a bestiary creator.

type EntityCreator

type EntityCreator interface {
	CreateFromStatblock(ctx context.Context, campaignID, userID, name, systemID string, statblock json.RawMessage) (entityID string, err error)
	// EntityExists reports whether an imported page is still in the campaign,
	// so an import record whose page was deleted does not block importing again.
	EntityExists(ctx context.Context, campaignID, entityID string) (bool, error)
}

EntityCreator creates campaign entities from imported bestiary statblocks. Implemented via an adapter wrapping the entities service in routes.go. systemID is the publication's game system, so the page lands on that system's creature type when the campaign has more than one.

type Favorite

type Favorite struct {
	UserID        string    `json:"user_id"`
	PublicationID string    `json:"publication_id"`
	CreatedAt     time.Time `json:"created_at"`
}

Favorite is a user's bookmark on a publication.

type Flag

type Flag struct {
	UserID        string    `json:"user_id"`
	PublicationID string    `json:"publication_id"`
	Reason        *string   `json:"reason,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
}

Flag tracks a single user's flag on a publication for moderation. The composite PK (user_id, publication_id) prevents duplicate flags.

type FlagInput

type FlagInput struct {
	Reason *string `json:"reason,omitempty"`
}

FlagInput is the request body for flagging a publication.

type Handler

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

Handler processes HTTP requests for the community bestiary plugin.

func NewHandler

func NewHandler(svc BestiaryService) *Handler

NewHandler creates a new bestiary Handler.

func (*Handler) AddFavorite

func (h *Handler) AddFavorite(c *echo.Context) error

AddFavorite toggles a favorite on a publication. POST /bestiary/:id/favorite

func (*Handler) AdminFlagged

func (h *Handler) AdminFlagged(c *echo.Context) error

AdminFlagged lists flagged publications for moderation review. GET /admin/bestiary/flagged

func (*Handler) AdminModerate

func (h *Handler) AdminModerate(c *echo.Context) error

AdminModerate performs a moderation action on a publication. POST /admin/bestiary/:id/moderate

func (*Handler) AdminModerationLog

func (h *Handler) AdminModerationLog(c *echo.Context) error

AdminModerationLog returns the moderation audit trail for a publication. GET /admin/bestiary/:id/moderation-log

func (*Handler) AdminStats

func (h *Handler) AdminStats(c *echo.Context) error

AdminStats returns aggregate bestiary statistics. GET /admin/bestiary/stats

func (*Handler) Browse

func (h *Handler) Browse(c *echo.Context) error

Browse lists published bestiary publications, paginated. GET /bestiary

func (*Handler) ChangeVisibility

func (h *Handler) ChangeVisibility(c *echo.Context) error

ChangeVisibility updates the visibility of a publication. PATCH /bestiary/:id/visibility

func (*Handler) Create

func (h *Handler) Create(c *echo.Context) error

Create publishes a new creature to the bestiary. POST /bestiary

func (*Handler) CreatorProfile

func (h *Handler) CreatorProfile(c *echo.Context) error

CreatorProfile returns a creator's public profile with stats. GET /bestiary/creators/:userId

func (*Handler) Delete

func (h *Handler) Delete(c *echo.Context) error

Delete archives a publication (soft-delete). DELETE /bestiary/:id

func (*Handler) FlagPublication

func (h *Handler) FlagPublication(c *echo.Context) error

FlagPublication flags a publication for moderation. POST /bestiary/:id/flag

func (*Handler) ForkToCampaign

func (h *Handler) ForkToCampaign(c *echo.Context) error

ForkToCampaign imports a publication as an editable copy into a campaign. POST /bestiary/:id/fork/:campaignId

func (*Handler) GetStatblock

func (h *Handler) GetStatblock(c *echo.Context) error

GetStatblock returns the raw statblock JSON for a publication. GET /bestiary/:slug/statblock

func (*Handler) ImportToCampaign

func (h *Handler) ImportToCampaign(c *echo.Context) error

ImportToCampaign imports a publication's creature into a campaign. POST /bestiary/:id/import/:campaignId

func (*Handler) ListFavorites

func (h *Handler) ListFavorites(c *echo.Context) error

ListFavorites returns the current user's favorited publications. GET /bestiary/favorites

func (*Handler) ListReviews

func (h *Handler) ListReviews(c *echo.Context) error

ListReviews returns paginated reviews for a publication. GET /bestiary/:slug/reviews

func (*Handler) MostImported

func (h *Handler) MostImported(c *echo.Context) error

MostImported returns publications with the most downloads. GET /bestiary/most-imported

func (*Handler) MyCreations

func (h *Handler) MyCreations(c *echo.Context) error

MyCreations lists the current user's publications across all visibility states. GET /bestiary/my-creations

func (*Handler) Newest

func (h *Handler) Newest(c *echo.Context) error

Newest returns the most recently published publications. GET /bestiary/newest

func (*Handler) RatePublication

func (h *Handler) RatePublication(c *echo.Context) error

RatePublication creates or updates a rating on a publication. POST /bestiary/:id/rate

func (*Handler) RemoveFavorite

func (h *Handler) RemoveFavorite(c *echo.Context) error

RemoveFavorite removes a favorite from a publication. DELETE /bestiary/:id/favorite

func (*Handler) RemoveRating

func (h *Handler) RemoveRating(c *echo.Context) error

RemoveRating removes a user's rating on a publication. DELETE /bestiary/:id/rate

func (*Handler) Search

func (h *Handler) Search(c *echo.Context) error

Search performs a filtered search across published publications. GET /bestiary/search

func (*Handler) Show

func (h *Handler) Show(c *echo.Context) error

Show returns a single publication by slug. GET /bestiary/:slug

func (*Handler) TopRated

func (h *Handler) TopRated(c *echo.Context) error

TopRated returns publications with the highest average rating. GET /bestiary/top-rated

func (*Handler) Trending

func (h *Handler) Trending(c *echo.Context) error

Trending returns publications sorted by trending score. GET /bestiary/trending

func (*Handler) Update

func (h *Handler) Update(c *echo.Context) error

Update modifies an existing publication. PUT /bestiary/:id

type Import

type Import struct {
	ID            string    `json:"id"`
	PublicationID string    `json:"publication_id"`
	UserID        string    `json:"user_id"`
	CampaignID    string    `json:"campaign_id"`
	EntityID      *string   `json:"entity_id,omitempty"`
	ImportedAt    time.Time `json:"imported_at"`
}

Import tracks a publication imported into a campaign as an entity.

type ImportResult

type ImportResult struct {
	EntityID      string `json:"entity_id"`
	CampaignID    string `json:"campaign_id"`
	PublicationID string `json:"publication_id"`
	CreatureName  string `json:"creature_name"`
}

ImportResult is the response returned after importing a publication into a campaign.

type ModerateInput

type ModerateInput struct {
	Action string  `json:"action"` // approve, archive, restore
	Reason *string `json:"reason,omitempty"`
}

ModerateInput is the request body for admin moderation actions.

type ModerationLogEntry

type ModerationLogEntry struct {
	ID            string    `json:"id"`
	PublicationID string    `json:"publication_id"`
	ModeratorID   string    `json:"moderator_id"`
	Action        string    `json:"action"`
	Reason        *string   `json:"reason,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
}

ModerationLogEntry records an admin moderation action on a publication.

type Publication

type Publication struct {
	ID               string          `json:"id"`
	CreatorID        string          `json:"creator_id"`
	SourceEntityID   *string         `json:"source_entity_id,omitempty"`
	SourceCampaignID *string         `json:"source_campaign_id,omitempty"`
	SystemID         string          `json:"system_id"`
	Name             string          `json:"name"`
	Slug             string          `json:"slug"`
	Description      *string         `json:"description,omitempty"`
	FlavorText       *string         `json:"flavor_text,omitempty"`
	ArtworkMediaID   *string         `json:"artwork_media_id,omitempty"`
	StatblockJSON    json.RawMessage `json:"statblock_json"`
	Version          int             `json:"version"`
	Tags             json.RawMessage `json:"tags,omitempty"`
	Organization     *string         `json:"organization,omitempty"`
	Role             *string         `json:"role,omitempty"`
	Level            *int            `json:"level,omitempty"`
	Downloads        int             `json:"downloads"`
	RatingSum        int             `json:"rating_sum"`
	RatingCount      int             `json:"rating_count"`
	Favorites        int             `json:"favorites"`
	Visibility       string          `json:"visibility"`
	FlaggedCount     int             `json:"flagged_count"`
	// PriorVisibility is where an approve or restore returns the publication to
	// after moderation hid it; internal, never serialized.
	PriorVisibility *string    `json:"-"`
	ReviewedBy      *string    `json:"reviewed_by,omitempty"`
	ReviewedAt      *time.Time `json:"reviewed_at,omitempty"`
	HubID           *string    `json:"hub_id,omitempty"`
	HubSyncedAt     *time.Time `json:"hub_synced_at,omitempty"`
	CreatedAt       time.Time  `json:"created_at"`
	UpdatedAt       time.Time  `json:"updated_at"`
}

Publication is a shared creature statblock published to the instance bestiary. Publications are instance-scoped (not campaign-scoped) — any authenticated user can browse them.

func (*Publication) ForViewer

func (p *Publication) ForViewer(userID string) *Publication

ForViewer returns the publication as userID may see it. Source campaign and page ids and the reviewing moderator belong to the creator's own campaign and the moderation team, so everyone else gets a copy without them.

func (*Publication) RatingAverage

func (p *Publication) RatingAverage() float64

RatingAverage returns the average rating, or 0 if unrated.

type PublicationListResult

type PublicationListResult struct {
	Results    []PublicationSummary `json:"results"`
	Total      int                  `json:"total"`
	Page       int                  `json:"page"`
	PerPage    int                  `json:"per_page"`
	TotalPages int                  `json:"total_pages"`
}

PublicationListResult is a paginated list of publication summaries.

type PublicationSummary

type PublicationSummary struct {
	ID            string          `json:"id"`
	CreatorID     string          `json:"creator_id"`
	SystemID      string          `json:"system_id"`
	Name          string          `json:"name"`
	Slug          string          `json:"slug"`
	Description   *string         `json:"description,omitempty"`
	Tags          json.RawMessage `json:"tags,omitempty"`
	Organization  *string         `json:"organization,omitempty"`
	Role          *string         `json:"role,omitempty"`
	Level         *int            `json:"level,omitempty"`
	Downloads     int             `json:"downloads"`
	RatingAverage float64         `json:"rating_average"`
	RatingCount   int             `json:"rating_count"`
	Favorites     int             `json:"favorites"`
	Version       int             `json:"version"`
	Visibility    string          `json:"visibility"`
	CreatedAt     time.Time       `json:"created_at"`
	UpdatedAt     time.Time       `json:"updated_at"`
}

PublicationSummary is the lightweight representation used in list/search views. It omits the full statblock_json to reduce payload size.

func SummaryFromPublication

func SummaryFromPublication(p *Publication) PublicationSummary

SummaryFromPublication converts a full Publication to a summary for list views.

type Rating

type Rating struct {
	ID            string    `json:"id"`
	PublicationID string    `json:"publication_id"`
	UserID        string    `json:"user_id"`
	Rating        int       `json:"rating"`
	ReviewText    *string   `json:"review_text,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

Rating is a user's 1-5 star rating with optional text review.

type ReviewListResult

type ReviewListResult struct {
	Reviews    []Rating `json:"reviews"`
	Total      int      `json:"total"`
	Page       int      `json:"page"`
	PerPage    int      `json:"per_page"`
	TotalPages int      `json:"total_pages"`
}

ReviewListResult is a paginated list of ratings with review text.

type SearchFilters

type SearchFilters struct {
	Query        string `json:"q,omitempty"`
	LevelMin     *int   `json:"level_min,omitempty"`
	LevelMax     *int   `json:"level_max,omitempty"`
	Organization string `json:"organization,omitempty"`
	Role         string `json:"role,omitempty"`
	Tags         string `json:"tags,omitempty"`
	CreatorID    string `json:"creator_id,omitempty"`
	SystemID     string `json:"system_id,omitempty"`
	Sort         string `json:"sort,omitempty"`
	Page         int    `json:"page"`
	PerPage      int    `json:"per_page"`
}

SearchFilters holds the query parameters for bestiary search.

type UpdatePublicationInput

type UpdatePublicationInput struct {
	Name          patch.Field[string] `json:"name"`
	Description   patch.Field[string] `json:"description"`
	FlavorText    patch.Field[string] `json:"flavor_text"`
	Tags          json.RawMessage     `json:"tags,omitempty"`
	StatblockJSON json.RawMessage     `json:"statblock_json,omitempty"`
}

UpdatePublicationInput is the validated input for updating a publication. It is a PARTIAL update: an absent key preserves, an explicit null clears a nullable column (description, flavor text) and preserves a required one (name, statblock, tags).

type UserFetcher

type UserFetcher interface {
	GetUserPublicInfo(ctx context.Context, userID string) (*UserInfo, error)
}

UserFetcher retrieves public user information for creator profiles. Implemented via an adapter wrapping the auth service in routes.go.

type UserInfo

type UserInfo struct {
	ID          string `json:"id"`
	DisplayName string `json:"display_name"`
	AvatarURL   string `json:"avatar_url,omitempty"`
}

UserInfo is the minimal user data needed for creator profiles. Populated by the UserFetcher cross-plugin interface.

Jump to

Keyboard shortcuts

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