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:
parent
43b8aac9a5
commit
c241399cab
5 changed files with 155 additions and 33 deletions
44
books.go
44
books.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue