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
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
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
|
|
}
|