Implement Project API methods

Add direct client methods for project/board operations:

- GetAllProjects(ctx) - list all accessible projects
- GetProjectByID(ctx, projectID) - get project by ID
- GetProjectByName(ctx, name) - get project by name

All methods:
- Use context for cancellation support
- Return ErrProjectNotFound when project doesn't exist
- Properly wrap errors with context

Closes: kanboard-api-apl
This commit is contained in:
Oliver Jakoubek 2026-01-15 18:21:42 +01:00
commit 7c8ebcc491
3 changed files with 269 additions and 1 deletions

49
projects.go Normal file
View file

@ -0,0 +1,49 @@
package kanboard
import (
"context"
"fmt"
)
// GetAllProjects returns all projects accessible to the authenticated user.
func (c *Client) GetAllProjects(ctx context.Context) ([]Project, error) {
var result []Project
if err := c.call(ctx, "getAllProjects", nil, &result); err != nil {
return nil, fmt.Errorf("getAllProjects: %w", err)
}
return result, nil
}
// GetProjectByID returns a project by its ID.
// Returns ErrProjectNotFound if the project does not exist.
func (c *Client) GetProjectByID(ctx context.Context, projectID int) (*Project, error) {
params := map[string]int{"project_id": projectID}
var result *Project
if err := c.call(ctx, "getProjectById", params, &result); err != nil {
return nil, fmt.Errorf("getProjectById: %w", err)
}
if result == nil {
return nil, fmt.Errorf("%w: project %d", ErrProjectNotFound, projectID)
}
return result, nil
}
// GetProjectByName returns a project by its name.
// Returns ErrProjectNotFound if the project does not exist.
func (c *Client) GetProjectByName(ctx context.Context, name string) (*Project, error) {
params := map[string]string{"name": name}
var result *Project
if err := c.call(ctx, "getProjectByName", params, &result); err != nil {
return nil, fmt.Errorf("getProjectByName: %w", err)
}
if result == nil {
return nil, fmt.Errorf("%w: project %q", ErrProjectNotFound, name)
}
return result, nil
}