Released v1
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.franklin.lab/steve.cliff/pcli/model"
|
||||
)
|
||||
|
||||
func (c *Client) ListProjects(ctx context.Context) ([]model.Project, error) {
|
||||
data, err := c.DoNoBody(ctx, "GET", "/api/projects")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Items []model.Project `json:"items"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal projects response: %w", err)
|
||||
}
|
||||
|
||||
return response.Items, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetProject(ctx context.Context, id string) (*model.Project, error) {
|
||||
data, err := c.DoNoBody(ctx, "GET", fmt.Sprintf("/api/projects/%s", id))
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user