From 605df92b375020597825ec9c322726b28db91c2a Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sat, 18 May 2024 20:39:57 +0100 Subject: [PATCH] checkpoint: add a model for list of lists --- cmd/enbas/add.go | 3 +++ cmd/enbas/remove.go | 3 +++ cmd/enbas/show.go | 5 +---- internal/client/lists.go | 2 +- internal/model/list.go | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cmd/enbas/add.go b/cmd/enbas/add.go index 096ee66..6ca7bfc 100644 --- a/cmd/enbas/add.go +++ b/cmd/enbas/add.go @@ -68,5 +68,8 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error { return fmt.Errorf("unable to add the accounts to the list; %w", err) } + fmt.Println("Successfully added the account(s) to the list.") + // TODO: ...then print the list with the accounts in them. + return nil } diff --git a/cmd/enbas/remove.go b/cmd/enbas/remove.go index 72c02fb..36ed293 100644 --- a/cmd/enbas/remove.go +++ b/cmd/enbas/remove.go @@ -68,5 +68,8 @@ func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error { return fmt.Errorf("unable to remove the accounts from the list; %w", err) } + fmt.Println("Successfully removed the account(s) to the list.") + // TODO: ...then print the list with the accounts in them. + return nil } diff --git a/cmd/enbas/show.go b/cmd/enbas/show.go index ef015c6..3d5ffe3 100644 --- a/cmd/enbas/show.go +++ b/cmd/enbas/show.go @@ -176,10 +176,7 @@ func (c *showCommand) showLists(gts *client.Client) error { } fmt.Println(utilities.HeaderFormat("LISTS")) - - for i := range lists { - fmt.Printf("\n%s\n", lists[i]) - } + fmt.Println(lists) return nil } diff --git a/internal/client/lists.go b/internal/client/lists.go index 6908a76..b1d022d 100644 --- a/internal/client/lists.go +++ b/internal/client/lists.go @@ -13,7 +13,7 @@ const ( listPath string = "/api/v1/lists" ) -func (g *Client) GetAllLists() ([]model.List, error) { +func (g *Client) GetAllLists() (model.Lists, error) { url := g.Authentication.Instance + listPath var lists []model.List diff --git a/internal/model/list.go b/internal/model/list.go index 9356de8..1a67d7a 100644 --- a/internal/model/list.go +++ b/internal/model/list.go @@ -87,3 +87,19 @@ func (l List) String() string { utilities.FieldFormat("Replies Policy:"), l.RepliesPolicy, ) } + +type Lists []List + +func (l Lists) String() string { + output := "" + + for i := range l { + output += fmt.Sprintf( + "\n%s (%s)", + l[i].Title, + l[i].ID, + ) + } + + return output +}