2026-01-30 09:36:58 +01:00
|
|
|
package bookstack
|
|
|
|
|
|
2026-01-30 09:49:49 +01:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
2026-01-30 09:36:58 +01:00
|
|
|
|
|
|
|
|
// 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) {
|
2026-01-30 09:49:49 +01:00
|
|
|
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
|
2026-01-30 09:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get retrieves a single book by ID.
|
|
|
|
|
func (s *BooksService) Get(ctx context.Context, id int) (*Book, error) {
|
2026-01-30 09:49:49 +01:00
|
|
|
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
|
2026-01-30 09:36:58 +01:00
|
|
|
}
|