bookstack-api/books.go
Oliver Jakoubek c241399cab 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.
2026-01-30 09:49:49 +01:00

31 lines
716 B
Go

package bookstack
import (
"context"
"fmt"
)
// BooksService handles operations on books.
type BooksService struct {
client *Client
}
// List returns a list of books with optional filtering.
func (s *BooksService) List(ctx context.Context, opts *ListOptions) ([]Book, error) {
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.
func (s *BooksService) Get(ctx context.Context, id int) (*Book, error) {
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
}