82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"git.franklin.lab/steve.cliff/pcli/model"
|
|
)
|
|
|
|
// ListCreateFields represents the fields required to create a list
|
|
type ListCreateFields struct {
|
|
Name string `json:"name"`
|
|
Position float64 `json:"position"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
// ListUpdateFields represents the fields that can be updated for a list
|
|
type ListUpdateFields struct {
|
|
Name *string `json:"name,omitempty"`
|
|
Position *float64 `json:"position,omitempty"`
|
|
Type *string `json:"type,omitempty"`
|
|
Color *string `json:"color,omitempty"`
|
|
BoardID *string `json:"boardId,omitempty"`
|
|
}
|
|
|
|
func (c *Client) CreateList(ctx context.Context, boardId string, fields ListCreateFields) (*model.List, error) {
|
|
data, err := c.Do(ctx, "POST", fmt.Sprintf("/api/boards/%s/lists", boardId), fields)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var response struct {
|
|
Item model.List `json:"item"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &response); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal list response: %w", err)
|
|
}
|
|
|
|
return &response.Item, nil
|
|
}
|
|
|
|
func (c *Client) GetList(ctx context.Context, id string) (*model.List, error) {
|
|
data, err := c.DoNoBody(ctx, "GET", fmt.Sprintf("/api/lists/%s", id))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var response struct {
|
|
Item model.List `json:"item"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &response); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal list response: %w", err)
|
|
}
|
|
|
|
return &response.Item, nil
|
|
}
|
|
|
|
func (c *Client) UpdateList(ctx context.Context, id string, fields ListUpdateFields) (*model.List, error) {
|
|
data, err := c.Do(ctx, "PATCH", fmt.Sprintf("/api/lists/%s", id), fields)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var response struct {
|
|
Item model.List `json:"item"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &response); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal list response: %w", err)
|
|
}
|
|
|
|
return &response.Item, nil
|
|
}
|
|
|
|
func (c *Client) DeleteList(ctx context.Context, id string) error {
|
|
_, err := c.DoNoBody(ctx, "DELETE", fmt.Sprintf("/api/lists/%s", id))
|
|
return err
|
|
}
|