checkpoint: adding statuses to bookmarks

This commit is contained in:
Dan Anglin 2024-06-03 05:10:50 +01:00
parent 4d30e643af
commit c0a56f0b7a
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 68 additions and 4 deletions

View file

@ -74,8 +74,39 @@ func (g *Client) GetBookmarks(limit int) (model.StatusList, error) {
}
if err := g.sendRequest(http.MethodGet, url, nil, &bookmarks.Statuses); err != nil {
return bookmarks, fmt.Errorf("received an error after sending the request to get the bookmarks: %w", err)
return bookmarks, fmt.Errorf(
"received an error after sending the request to get the bookmarks: %w",
err,
)
}
return bookmarks, nil
}
func (g *Client) AddStatusToBookmarks(statusID string) error {
path := fmt.Sprintf("/api/v1/statuses/%s/bookmark", statusID)
url := g.Authentication.Instance + path
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(
"received an error after sending the request to add the status to the list of bookmarks: %w",
err,
)
}
return nil
}
func (g *Client) RemoveStatusFromBookmarks(statusID string) error {
path := fmt.Sprintf("/api/v1/statuses/%s/unbookmark", statusID)
url := g.Authentication.Instance + path
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf(
"received an error after sending the request to remove the status from the list of bookmarks: %w",
err,
)
}
return nil
}

View file

@ -18,6 +18,7 @@ type AddExecutor struct {
resourceType string
toResourceType string
listID string
statusID string
accountNames AccountNames
content string
}
@ -34,7 +35,8 @@ func NewAddExecutor(tlf TopLevelFlags, name, summary string) *AddExecutor {
addExe.StringVar(&addExe.resourceType, flagType, "", "specify the resource type to add (e.g. account, note)")
addExe.StringVar(&addExe.toResourceType, flagTo, "", "specify the target resource type to add to (e.g. list, account, etc)")
addExe.StringVar(&addExe.listID, flagListID, "", "the ID of the list to add to")
addExe.Var(&addExe.accountNames, flagAccountName, "the name of the account to add to the resource")
addExe.StringVar(&addExe.statusID, flagStatusID, "", "the ID of the status")
addExe.Var(&addExe.accountNames, flagAccountName, "the name of the account")
addExe.StringVar(&addExe.content, flagContent, "", "the content of the note")
addExe.Usage = commandUsageFunc(name, summary, addExe.FlagSet)
@ -50,6 +52,7 @@ func (a *AddExecutor) Execute() error {
funcMap := map[string]func(*client.Client) error{
resourceList: a.addToList,
resourceAccount: a.addToAccount,
resourceBookmarks: a.addToBookmarks,
}
doFunc, ok := funcMap[a.toResourceType]
@ -151,3 +154,33 @@ func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
return nil
}
func (a *AddExecutor) addToBookmarks(gtsClient *client.Client) error {
funcMap := map[string]func(*client.Client) error{
resourceStatus: a.addStatusToBookmarks,
}
doFunc, ok := funcMap[a.resourceType]
if !ok {
return UnsupportedAddOperationError{
ResourceType: a.resourceType,
AddToResourceType: a.toResourceType,
}
}
return doFunc(gtsClient)
}
func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
if a.statusID == "" {
return FlagNotSetError{flagText: flagStatusID}
}
if err := gtsClient.AddStatusToBookmarks(a.statusID); err != nil {
return fmt.Errorf("unable to add the status to your bookmarks: %w", err)
}
fmt.Println("Successfully added the status to your bookmarks.")
return nil
}