// SPDX-License-Identifier: AGPL-3.0-or-later package httpapi import ( "context" "net/http" "docwell/server/internal/access" "docwell/server/internal/directory" ) // CommentService is the part of directory.Service for inline comments. type CommentService interface { ListComments(ctx context.Context, c access.Caller, pageID string) ([]directory.Comment, error) CreateComment(ctx context.Context, c access.Caller, pageID string, in directory.CreateCommentInput) (directory.Comment, error) DeleteComment(ctx context.Context, c access.Caller, id string) error } func (a *api) commentRoutes(mux *routeMux) { mux.HandleFunc("GET /api/v1/pages/{id}/comments", a.requireUser(func(w http.ResponseWriter, r *http.Request) { list, err := a.dir.ListComments(r.Context(), caller(r), r.PathValue("id")) a.respond(w, list, err) })) mux.HandleFunc("POST /api/v1/pages/{id}/comments", a.requireUser(func(w http.ResponseWriter, r *http.Request) { var in directory.CreateCommentInput if !a.decode(w, r, &in) { return } cm, err := a.dir.CreateComment(r.Context(), caller(r), r.PathValue("id"), in) a.respondStatus(w, http.StatusCreated, cm, err) })) mux.HandleFunc("DELETE /api/v1/comments/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) { a.respondNoContent(w, a.dir.DeleteComment(r.Context(), caller(r), r.PathValue("id"))) })) }