api

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 11 Imported by: 2 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

Index

Constants

This section is empty.

Variables

View Source
var ErrContentNotFound = errors.New("comments: content not found")

ErrContentNotFound is returned by the ContentResolver when no published content matches the slug. Core translates the content lookup failure to it so this package never imports the content domain.

Functions

This section is empty.

Types

type CommentHandler

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

CommentHandler serves the browser-realm comment surface.

func NewCommentHandler

func NewCommentHandler(
	commentService CommentService,
	content ContentResolver,
	opts ...CommentHandlerOption,
) *CommentHandler

NewCommentHandler constructs a CommentHandler backed by the given comment service and published-content resolver.

func (*CommentHandler) CreateComment

func (h *CommentHandler) CreateComment(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) DeleteComment

func (h *CommentHandler) DeleteComment(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) DeleteOwnComment

func (h *CommentHandler) DeleteOwnComment(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) GetComments

func (h *CommentHandler) GetComments(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) GetCommentsForModeration

func (h *CommentHandler) GetCommentsForModeration(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) GetMyComments

func (h *CommentHandler) GetMyComments(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) GetPendingComments

func (h *CommentHandler) GetPendingComments(w http.ResponseWriter, r *http.Request)

func (*CommentHandler) UpdateCommentStatus

func (h *CommentHandler) UpdateCommentStatus(w http.ResponseWriter, r *http.Request)

type CommentHandlerOption

type CommentHandlerOption func(*CommentHandler)

CommentHandlerOption configures a CommentHandler. A role service makes the comment capability config-driven; without one every authenticated user may comment (the legacy behavior).

func WithCommentRoleService

func WithCommentRoleService(rs RoleCapabilities) CommentHandlerOption

WithCommentRoleService attaches the config-driven role registry so posting comments is gated by the caller's CanComment capability.

type CommentResponse

type CommentResponse struct {
	ID        int       `json:"id"`
	Comment   string    `json:"comment"`
	Author    string    `json:"author,omitempty"`
	Username  string    `json:"username,omitempty"`
	Role      string    `json:"role,omitempty"`
	Status    string    `json:"status,omitempty"`
	CreatedAt time.Time `json:"createdAt"`
}

CommentResponse is the browser-facing representation of a comment.

type CommentService

type CommentService interface {
	SubmitComment(ctx context.Context, contentID int, principal kernel.Principal, req commentdomain.CreateCommentRequest) (*commentdomain.Comment, error)
	GetComment(ctx context.Context, commentID int) (*commentdomain.Comment, error)
	GetCommentsForContent(ctx context.Context, contentID int) ([]*commentdomain.Comment, error)
	GetCommentsForModeration(ctx context.Context, contentID int) ([]*commentdomain.Comment, error)
	GetCommentsByUserID(ctx context.Context, userID int) ([]*commentdomain.Comment, error)
	GetCommentsByStatus(ctx context.Context, status commentdomain.CommentStatus) ([]*commentdomain.Comment, error)
	CountComments(ctx context.Context, userID int) (int, error)
	UpdateCommentStatus(ctx context.Context, commentID int, status commentdomain.CommentStatus) error
	DeleteComment(ctx context.Context, commentID int) error
	DeleteOwnComment(ctx context.Context, commentID int, principal kernel.Principal) error
}

CommentService is the narrow slice of comment operations this handler depends on. *commentdomain.Service satisfies it.

type ContentRef

type ContentRef struct {
	ID            int
	AllowComments bool
}

ContentRef is the comment-relevant projection of a published content item: its ID for scoping and its AllowComments flag for gating.

type ContentResolver

type ContentResolver func(ctx context.Context, slug, language string) (ContentRef, error)

ContentResolver resolves a published slug to its comment-relevant facts. Core satisfies it with a closure over the content service (which cannot be imported here); tests stub it with a func literal.

type CreateCommentRequest

type CreateCommentRequest struct {
	Comment string `json:"comment"`
}

CreateCommentRequest is the browser comment-create payload.

type PendingCommentResponse

type PendingCommentResponse struct {
	ID           int       `json:"id"`
	ContentID    int       `json:"contentId"`
	ContentTitle string    `json:"contentTitle,omitempty"`
	ContentSlug  string    `json:"contentSlug,omitempty"`
	Comment      string    `json:"comment"`
	Author       string    `json:"author,omitempty"`
	Username     string    `json:"username,omitempty"`
	Status       string    `json:"status,omitempty"`
	CreatedAt    time.Time `json:"createdAt"`
}

PendingCommentResponse is the admin-facing representation of a comment awaiting moderation, enriched with the content item it belongs to.

type RoleCapabilities

type RoleCapabilities interface {
	CanComment(name string) bool
}

RoleCapabilities is the narrow role-registry seam this handler depends on. Core satisfies it with an adapter over *role.Service (which cannot be imported here); the users module implements it natively when it lands.

type UpdateCommentStatusRequest

type UpdateCommentStatusRequest struct {
	Status string `json:"status"`
}

UpdateCommentStatusRequest is the browser moderation payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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