posts

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: 14 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 posts implements the entity posts widget for Chronicle. Posts are named content sections attached to entities, displayed below the main entry on the entity show page. Each post has its own TipTap rich text content, visibility controls, and sort order for drag-to-reorder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

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

RegisterRoutes sets up all entity post routes on the given Echo instance. Posts are scoped to a campaign and require campaign membership.

Permissions:

  • Player (read): list posts for an entity
  • Scribe (write): create, update, delete, and reorder posts

Types

type CreatePostRequest

type CreatePostRequest struct {
	Name      string          `json:"name"`
	Entry     json.RawMessage `json:"entry,omitempty"`
	EntryHTML *string         `json:"entryHtml,omitempty"`
	IsPrivate bool            `json:"isPrivate"`
}

CreatePostRequest holds the data submitted when creating a new post.

type EntityGate

type EntityGate interface {
	// ResolveViewableEntity returns the entity's owning campaign ID and whether
	// the viewer (role, userID) may view it. A missing entity returns a
	// not-found error. Mirrors the entity Show page gate.
	ResolveViewableEntity(ctx context.Context, entityID string, role int, userID string) (campaignID string, canView bool, err error)
}

EntityGate is the narrow cross-plugin seam the posts widget uses to honor entity visibility + campaign binding without importing the entities repo (plugin isolation). Implemented by an adapter over the entity service, wired in app/routes.go.

type Handler

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

Handler handles HTTP requests for entity post operations. Handlers are thin: bind request, call service, render response. No business logic.

func NewHandler

func NewHandler(service PostService) *Handler

NewHandler creates a new post handler backed by the given service.

func (*Handler) CreatePost

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

CreatePost creates a new post attached to an entity. POST /campaigns/:id/entities/:eid/posts

func (*Handler) DeletePost

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

DeletePost removes a post. DELETE /campaigns/:id/entities/:eid/posts/:pid

func (*Handler) ListPosts

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

ListPosts returns all posts for an entity as JSON. GET /campaigns/:id/entities/:eid/posts

func (*Handler) ReorderPosts

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

ReorderPosts updates the sort order for posts within an entity. PUT /campaigns/:id/entities/:eid/posts/reorder

func (*Handler) SetEntityGate

func (h *Handler) SetEntityGate(gate EntityGate)

SetEntityGate injects the entity-visibility gate. Called during app wiring. When set, the public list endpoint enforces entity privacy + campaign binding.

func (*Handler) SetMentionHider

func (h *Handler) SetMentionHider(m sanitize.MentionHider)

SetMentionHider injects the check that hides mentions of pages a reader can't open. Unset, every mention in a served post is hidden.

func (*Handler) UpdatePost

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

UpdatePost updates a post's name, content, or visibility. PUT /campaigns/:id/entities/:eid/posts/:pid

type Post

type Post struct {
	ID         string          `json:"id"`
	EntityID   string          `json:"entityId"`
	CampaignID string          `json:"campaignId"`
	Name       string          `json:"name"`
	Entry      json.RawMessage `json:"entry,omitempty"`
	EntryHTML  *string         `json:"entryHtml,omitempty"`
	IsPrivate  bool            `json:"isPrivate"`
	SortOrder  int             `json:"sortOrder"`
	CreatedBy  string          `json:"createdBy"`
	CreatedAt  time.Time       `json:"createdAt"`
	UpdatedAt  time.Time       `json:"updatedAt"`
}

Post represents a single sub-note/post attached to an entity.

type PostRepository

type PostRepository interface {
	// Create inserts a new post into the database.
	Create(ctx context.Context, post *Post) error
	// FindByID returns a single post by its ID.
	FindByID(ctx context.Context, id string) (*Post, error)
	// ListByEntity returns all posts for an entity within a campaign, ordered by
	// sort_order. The campaign_id predicate is defense-in-depth against
	// cross-campaign reads (the handler is the primary IDOR gate). When
	// includeDMOnly is false, DM-only posts are filtered out.
	ListByEntity(ctx context.Context, campaignID, entityID string, includeDMOnly bool) ([]Post, error)
	// Update modifies an existing post.
	Update(ctx context.Context, post *Post) error
	// Delete removes a post by its ID.
	Delete(ctx context.Context, id string) error
	// Reorder updates the sort_order for a list of post IDs within an entity.
	Reorder(ctx context.Context, campaignID, entityID string, postIDs []string) error
}

PostRepository defines the data access interface for entity posts.

func NewPostRepository

func NewPostRepository(db *sql.DB) PostRepository

NewPostRepository creates a new MariaDB-backed post repository.

type PostService

type PostService interface {
	// Create creates a new post attached to an entity.
	Create(ctx context.Context, campaignID, entityID, userID, name string, req CreatePostRequest) (*Post, error)
	// GetByID returns a post by ID.
	GetByID(ctx context.Context, id string) (*Post, error)
	// ListByEntity returns all posts for an entity within a campaign, filtering
	// DM-only based on role. campaignID scopes the query (defense-in-depth).
	ListByEntity(ctx context.Context, campaignID, entityID string, includeDMOnly bool) ([]Post, error)
	// Update modifies a post's name, content, or visibility.
	Update(ctx context.Context, id string, req UpdatePostRequest) (*Post, error)
	// Delete removes a post.
	Delete(ctx context.Context, id string) error
	// Reorder updates the sort order for posts within an entity.
	Reorder(ctx context.Context, campaignID, entityID string, postIDs []string) error
}

PostService defines the business logic interface for entity posts.

func NewPostService

func NewPostService(repo PostRepository) PostService

NewPostService creates a new post service backed by the given repository.

type ReorderPostsRequest

type ReorderPostsRequest struct {
	PostIDs []string `json:"postIds"`
}

ReorderPostsRequest holds the ordered list of post IDs for reordering.

type UpdatePostRequest

type UpdatePostRequest struct {
	Name      *string         `json:"name,omitempty"`
	Entry     json.RawMessage `json:"entry,omitempty"`
	EntryHTML *string         `json:"entryHtml,omitempty"`
	IsPrivate *bool           `json:"isPrivate,omitempty"`
}

UpdatePostRequest holds the data submitted when updating a post.

Jump to

Keyboard shortcuts

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