Added create and delete operations for projects and boards with validation and error handling

This commit is contained in:
Steve Cliff
2026-02-17 07:47:49 +00:00
parent c03d05734a
commit c15a48cda3
15 changed files with 571 additions and 4 deletions
+28
View File
@@ -9,6 +9,12 @@ import (
"git.franklin.lab/steve.cliff/pcli/model"
)
// BoardCreateFields represents the fields required to create a board
type BoardCreateFields struct {
Name string `json:"name"`
Position float64 `json:"position"`
}
func (c *Client) ListBoards(ctx context.Context) ([]model.Board, error) {
data, err := c.DoNoBody(ctx, "GET", "/api/projects")
if err != nil {
@@ -96,3 +102,25 @@ func (c *Client) ListBoardActions(ctx context.Context, boardId string, limit int
return all, nil
}
func (c *Client) CreateBoard(ctx context.Context, projectId string, fields BoardCreateFields) (*model.Board, error) {
data, err := c.Do(ctx, "POST", fmt.Sprintf("/api/projects/%s/boards", projectId), fields)
if err != nil {
return nil, err
}
var response struct {
Item model.Board `json:"item"`
}
if err := json.Unmarshal(data, &response); err != nil {
return nil, fmt.Errorf("failed to unmarshal board response: %w", err)
}
return &response.Item, nil
}
func (c *Client) DeleteBoard(ctx context.Context, id string) error {
_, err := c.DoNoBody(ctx, "DELETE", fmt.Sprintf("/api/boards/%s", id))
return err
}
+29
View File
@@ -8,6 +8,13 @@ import (
"git.franklin.lab/steve.cliff/pcli/model"
)
// ProjectCreateFields represents the fields required to create a project
type ProjectCreateFields struct {
Type string `json:"type"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
}
func (c *Client) ListProjects(ctx context.Context) ([]model.Project, error) {
data, err := c.DoNoBody(ctx, "GET", "/api/projects")
if err != nil {
@@ -41,3 +48,25 @@ func (c *Client) GetProject(ctx context.Context, id string) (*model.Project, err
return &response.Item, nil
}
func (c *Client) CreateProject(ctx context.Context, fields ProjectCreateFields) (*model.Project, error) {
data, err := c.Do(ctx, "POST", "/api/projects", fields)
if err != nil {
return nil, err
}
var response struct {
Item model.Project `json:"item"`
}
if err := json.Unmarshal(data, &response); err != nil {
return nil, fmt.Errorf("failed to unmarshal project response: %w", err)
}
return &response.Item, nil
}
func (c *Client) DeleteProject(ctx context.Context, id string) error {
_, err := c.DoNoBody(ctx, "DELETE", fmt.Sprintf("/api/projects/%s", id))
return err
}