Released v1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.franklin.lab/steve.cliff/pcli/model"
|
||||
)
|
||||
|
||||
func (c *Client) CreateTask(ctx context.Context, taskListId string, fields map[string]any) (*model.Task, error) {
|
||||
data, err := c.Do(ctx, "POST", fmt.Sprintf("/api/task-lists/%s/tasks", taskListId), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Item model.Task `json:"item"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal task response: %w", err)
|
||||
}
|
||||
|
||||
return &response.Item, nil
|
||||
}
|
||||
|
||||
func (c *Client) UpdateTask(ctx context.Context, id string, fields map[string]any) (*model.Task, error) {
|
||||
data, err := c.Do(ctx, "PATCH", fmt.Sprintf("/api/tasks/%s", id), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Item model.Task `json:"item"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal task response: %w", err)
|
||||
}
|
||||
|
||||
return &response.Item, nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteTask(ctx context.Context, id string) error {
|
||||
_, err := c.DoNoBody(ctx, "DELETE", fmt.Sprintf("/api/tasks/%s", id))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user