feat(bookstack-api-7qx): implement Comments CRUD
Add CommentsService with List, Get, Create, Update, Delete. Support nested comments via parent_id. Register service on Client. Add types and tests.
This commit is contained in:
parent
256361e90b
commit
0a1cd5ef38
6 changed files with 201 additions and 5 deletions
56
comments.go
Normal file
56
comments.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package bookstack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CommentsService handles operations on comments.
|
||||
type CommentsService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// List returns a list of comments with optional filtering.
|
||||
func (s *CommentsService) List(ctx context.Context, opts *ListOptions) ([]Comment, error) {
|
||||
var resp listResponse[Comment]
|
||||
err := s.client.do(ctx, "GET", "/api/comments"+opts.queryString(), nil, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
// Get retrieves a single comment by ID.
|
||||
func (s *CommentsService) Get(ctx context.Context, id int) (*Comment, error) {
|
||||
var c Comment
|
||||
err := s.client.do(ctx, "GET", fmt.Sprintf("/api/comments/%d", id), nil, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// Create creates a new comment on a page.
|
||||
func (s *CommentsService) Create(ctx context.Context, req *CommentCreateRequest) (*Comment, error) {
|
||||
var c Comment
|
||||
err := s.client.do(ctx, "POST", "/api/comments", req, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// Update updates an existing comment.
|
||||
func (s *CommentsService) Update(ctx context.Context, id int, req *CommentUpdateRequest) (*Comment, error) {
|
||||
var c Comment
|
||||
err := s.client.do(ctx, "PUT", fmt.Sprintf("/api/comments/%d", id), req, &c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// Delete deletes a comment by ID.
|
||||
func (s *CommentsService) Delete(ctx context.Context, id int) error {
|
||||
return s.client.do(ctx, "DELETE", fmt.Sprintf("/api/comments/%d", id), nil, nil)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue