Implement Category API methods (GetAllCategories, GetCategory)

- GetAllCategories returns all categories for a project
- GetCategory returns a single category by ID
- Returns ErrCategoryNotFound for non-existent categories
- Added ErrCategoryNotFound to IsNotFound helper
- Comprehensive test coverage
This commit is contained in:
Oliver Jakoubek 2026-01-15 18:25:12 +01:00
commit fc4577e729
4 changed files with 207 additions and 2 deletions

35
categories.go Normal file
View file

@ -0,0 +1,35 @@
package kanboard
import (
"context"
"fmt"
)
// GetAllCategories returns all categories for a project.
func (c *Client) GetAllCategories(ctx context.Context, projectID int) ([]Category, error) {
params := map[string]int{"project_id": projectID}
var result []Category
if err := c.call(ctx, "getAllCategories", params, &result); err != nil {
return nil, fmt.Errorf("getAllCategories: %w", err)
}
return result, nil
}
// GetCategory returns a category by its ID.
// Returns ErrCategoryNotFound if the category does not exist.
func (c *Client) GetCategory(ctx context.Context, categoryID int) (*Category, error) {
params := map[string]int{"category_id": categoryID}
var result *Category
if err := c.call(ctx, "getCategory", params, &result); err != nil {
return nil, fmt.Errorf("getCategory: %w", err)
}
if result == nil {
return nil, fmt.Errorf("%w: category %d", ErrCategoryNotFound, categoryID)
}
return result, nil
}