the client can get and update a single list
This commit is contained in:
parent
cb2c90050d
commit
6fed0edf4d
2 changed files with 51 additions and 3 deletions
|
@ -164,7 +164,7 @@ func (c *showCommand) showTimeline(gts *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *showCommand) showLists(gts *client.Client) error {
|
func (c *showCommand) showLists(gts *client.Client) error {
|
||||||
lists, err := gts.GetLists()
|
lists, err := gts.GetAllLists()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the lists; %w", err)
|
return fmt.Errorf("unable to retrieve the lists; %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,12 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *Client) GetLists() ([]model.List, error) {
|
const (
|
||||||
url := g.Authentication.Instance + "/api/v1/lists"
|
listPath string = "/api/v1/lists"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (g *Client) GetAllLists() ([]model.List, error) {
|
||||||
|
url := g.Authentication.Instance + listPath
|
||||||
|
|
||||||
var lists []model.List
|
var lists []model.List
|
||||||
|
|
||||||
|
@ -24,6 +28,21 @@ func (g *Client) GetLists() ([]model.List, error) {
|
||||||
return lists, nil
|
return lists, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Client) GetList(listID string) (model.List, error) {
|
||||||
|
url := g.Authentication.Instance + listPath + "/" + listID
|
||||||
|
|
||||||
|
var list model.List
|
||||||
|
|
||||||
|
if err := g.sendRequest(http.MethodGet, url, nil, &list); err != nil {
|
||||||
|
return model.List{}, fmt.Errorf(
|
||||||
|
"received an error after sending the request to get the list; %w",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Client) CreateList(title string, repliesPolicy model.ListRepliesPolicy) (model.List, error) {
|
func (g *Client) CreateList(title string, repliesPolicy model.ListRepliesPolicy) (model.List, error) {
|
||||||
params := struct {
|
params := struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -53,6 +72,35 @@ func (g *Client) CreateList(title string, repliesPolicy model.ListRepliesPolicy)
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Client) UpdateList(listToUpdate model.List) (model.List, error) {
|
||||||
|
params := struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
RepliesPolicy model.ListRepliesPolicy `json:"replies_policy"`
|
||||||
|
}{
|
||||||
|
Title: listToUpdate.Title,
|
||||||
|
RepliesPolicy: listToUpdate.RepliesPolicy,
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := json.Marshal(params)
|
||||||
|
if err != nil {
|
||||||
|
return model.List{}, fmt.Errorf("unable to marshal the request body; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody := bytes.NewBuffer(data)
|
||||||
|
url := g.Authentication.Instance + listPath + "/" + listToUpdate.ID
|
||||||
|
|
||||||
|
var updatedList model.List
|
||||||
|
|
||||||
|
if err := g.sendRequest(http.MethodPut, url, requestBody, &updatedList); err != nil {
|
||||||
|
return model.List{}, fmt.Errorf(
|
||||||
|
"received an error after sending the request to update the list; %w",
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedList, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Client) DeleteList(listID string) error {
|
func (g *Client) DeleteList(listID string) error {
|
||||||
url := g.Authentication.Instance + "/api/v1/lists/" + listID
|
url := g.Authentication.Instance + "/api/v1/lists/" + listID
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue