49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"git.franklin.lab/steve.cliff/pcli/model"
|
|
)
|
|
|
|
func (c *Client) CreateLabel(ctx context.Context, boardId string, fields map[string]any) (*model.Label, error) {
|
|
data, err := c.Do(ctx, "POST", fmt.Sprintf("/api/boards/%s/labels", boardId), fields)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var response struct {
|
|
Item model.Label `json:"item"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &response); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal label response: %w", err)
|
|
}
|
|
|
|
return &response.Item, nil
|
|
}
|
|
|
|
func (c *Client) UpdateLabel(ctx context.Context, id string, fields map[string]any) (*model.Label, error) {
|
|
data, err := c.Do(ctx, "PATCH", fmt.Sprintf("/api/labels/%s", id), fields)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var response struct {
|
|
Item model.Label `json:"item"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &response); err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal label response: %w", err)
|
|
}
|
|
|
|
return &response.Item, nil
|
|
}
|
|
|
|
func (c *Client) DeleteLabel(ctx context.Context, id string) error {
|
|
_, err := c.DoNoBody(ctx, "DELETE", fmt.Sprintf("/api/labels/%s", id))
|
|
return err
|
|
}
|