Documentation
¶
Overview ¶
Package comments implements flat, chronological comment threads on file/folder nodes (v0.6 "Çalışma" (Work) wave, migration 00020).
Access model (enforced by the caller/handler via acl.Resolver): anyone who can SEE a node (≥viewer) may read AND write comments on it; deleting a comment is author-or-admin (enforced HERE, since it depends on comment ownership, not node ACL). Rows are soft-deleted; hard removal rides the nodes FK CASCADE plus the trash purge hook.
Index ¶
Constants ¶
const MaxBodyLen = 5000
MaxBodyLen is the maximum comment length in runes (spec: 1..5000).
Variables ¶
var ( // ErrBadBody — empty (after trim) or over-length body → 400. ErrBadBody = errors.New("comments: body must be 1..5000 characters") // ErrNotFound — comment or node missing/soft-deleted → 404. ErrNotFound = errors.New("comments: not found") // ErrForbidden — delete by someone who is neither author nor admin → 403. ErrForbidden = errors.New("comments: forbidden") )
Sentinel errors the handler maps to HTTP statuses.
Functions ¶
Types ¶
type Service ¶
Service is the comment engine. Thin by design: validation + ownership rules here, SQL in db.Store, node-visibility ACL in the handler.
func (*Service) Add ¶
func (s *Service) Add(ctx context.Context, nodeID, userID int64, body string) (*model.NodeComment, error)
Add validates the body (1..5000 runes after trim) and inserts a comment by user on node. The caller must have verified node visibility already.
func (*Service) Delete ¶
func (s *Service) Delete(ctx context.Context, id int64, user *model.User) (*model.NodeComment, error)
Delete soft-deletes a comment. Only the comment's author or an admin account may delete; anyone else gets ErrForbidden. A missing (or already deleted) comment yields ErrNotFound.