feat(bookstack-api-9xo): implement BooksService List and Get

Add listResponse generic type and ListOptions.queryString() helper.
Implement BooksService.List with pagination support and Get with
proper error handling. Include mock server tests.
This commit is contained in:
Oliver Jakoubek 2026-01-30 09:49:49 +01:00
commit c241399cab
5 changed files with 155 additions and 33 deletions

View file

@ -1,6 +1,9 @@
package bookstack
import "context"
import (
"context"
"fmt"
)
// BooksService handles operations on books.
type BooksService struct {
@ -8,36 +11,21 @@ type BooksService struct {
}
// List returns a list of books with optional filtering.
// TODO: Implement API call to GET /api/books
func (s *BooksService) List(ctx context.Context, opts *ListOptions) ([]Book, error) {
// Placeholder for future implementation
return nil, nil
var resp listResponse[Book]
err := s.client.do(ctx, "GET", "/api/books"+opts.queryString(), nil, &resp)
if err != nil {
return nil, err
}
return resp.Data, nil
}
// Get retrieves a single book by ID.
// TODO: Implement API call to GET /api/books/{id}
func (s *BooksService) Get(ctx context.Context, id int) (*Book, error) {
// Placeholder for future implementation
return nil, nil
}
// Create creates a new book.
// TODO: Implement API call to POST /api/books
func (s *BooksService) Create(ctx context.Context, book *Book) (*Book, error) {
// Placeholder for future implementation
return nil, nil
}
// Update updates an existing book.
// TODO: Implement API call to PUT /api/books/{id}
func (s *BooksService) Update(ctx context.Context, id int, book *Book) (*Book, error) {
// Placeholder for future implementation
return nil, nil
}
// Delete deletes a book by ID.
// TODO: Implement API call to DELETE /api/books/{id}
func (s *BooksService) Delete(ctx context.Context, id int) error {
// Placeholder for future implementation
return nil
var book Book
err := s.client.do(ctx, "GET", fmt.Sprintf("/api/books/%d", id), nil, &book)
if err != nil {
return nil, err
}
return &book, nil
}