Documentation
¶
Index ¶
- Variables
- type Contribution
- type Handler
- func (h *Handler) Approve(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Get(w http.ResponseWriter, r *http.Request)
- func (h *Handler) List(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListMine(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Reject(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Submit(w http.ResponseWriter, r *http.Request)
- type ListFilter
- type Service
- func (s *Service) Approve(ctx context.Context, id uuid.UUID, reviewerID uint) (*Contribution, error)
- func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Contribution, error)
- func (s *Service) List(ctx context.Context, f ListFilter) ([]Contribution, error)
- func (s *Service) Reject(ctx context.Context, id uuid.UUID, reviewerID uint) (*Contribution, error)
- func (s *Service) Submit(ctx context.Context, workID uuid.UUID, contributorID uint, ...) (*Contribution, error)
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("contribution not found") ErrWorkNotFound = errors.New("work not found") ErrEmptyPatch = errors.New("patch is empty") ErrAlreadyDecided = errors.New("contribution already decided") // ErrInvalidPatch is wrapped with a user-facing reason by validatePatch; // the handler returns the full message as a 400. ErrInvalidPatch = errors.New("invalid patch") )
Functions ¶
This section is empty.
Types ¶
type Contribution ¶
type Contribution struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
WorkID uuid.UUID `gorm:"type:uuid;not null;index" json:"work_id"`
ContributorID uint `gorm:"not null;index" json:"contributor_id"`
Status Status `gorm:"not null;index;default:pending" json:"status"`
Patch datatypes.JSON `json:"patch"`
ReviewerID *uint `gorm:"index" json:"reviewer_id,omitempty"`
DecidedAt *time.Time `json:"decided_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// ContributorName is populated by the service layer via a users-table
// lookup (gorm:"-" so AutoMigrate ignores it). It's what the moderator
// queue UI displays under each card — empty for users that no longer
// exist, which the UI falls back to "user #ID" on.
ContributorName string `gorm:"-" json:"contributor_name,omitempty"`
// Current holds the target Work's present value for each field named in
// Patch — i.e. the "old" side of the moderator-queue diff. Populated by
// the service via a batch Works lookup (gorm:"-"); keys mirror Patch so
// the UI can pair old↔new. Resolved at read time, so it reflects the
// Work as it stands now (another approval may have moved it since
// submission). Omitted from the wire when empty.
Current map[string]any `gorm:"-" json:"current,omitempty"`
}
Contribution is a proposed edit to a Work. The Patch column stores a flat partial-object of the form {"title": "...", "authors": "..."}; only whitelisted keys (see service.allowedPatchFields) survive the Approve apply step. datatypes.JSON picks JSONB on Postgres and TEXT on sqlite so smoke tests stay portable.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func (*Handler) ListMine ¶
func (h *Handler) ListMine(w http.ResponseWriter, r *http.Request)
ListMine returns the calling user's own contributions. Separate route (/me/contributions) rather than a ?contributor=me pseudo-value on /contributions, so the public List handler stays trivially cacheable and auth is enforced by the router rather than re-parsed here.
type ListFilter ¶
ListFilter narrows List results. Zero-valued fields are ignored.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) Approve ¶
func (s *Service) Approve(ctx context.Context, id uuid.UUID, reviewerID uint) (*Contribution, error)
Approve applies the contribution's whitelisted patch fields to the target Work and marks the contribution approved. Returns ErrAlreadyDecided if the contribution isn't pending — including when another moderator decides it concurrently (see transition).
func (*Service) List ¶
func (s *Service) List(ctx context.Context, f ListFilter) ([]Contribution, error)