From b12f2328b3fc1d82303c05ab0e9d526076d2534f Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 21 May 2024 22:23:44 +0100 Subject: [PATCH] add client method to add a private note --- internal/client/accounts.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/client/accounts.go b/internal/client/accounts.go index 490e8a3..0513eb2 100644 --- a/internal/client/accounts.go +++ b/internal/client/accounts.go @@ -158,3 +158,25 @@ func (g *Client) GetBlockedAccounts(limit int) (model.AccountList, error) { return blocked, nil } + +func (g *Client) SetPrivateNote(accountID, note string) error { + form := struct { + Comment string `json:"comment"` + }{ + Comment: note, + } + + data, err := json.Marshal(form) + if err != nil { + return fmt.Errorf("unable to marshal the form; %w", err) + } + + requestBody := bytes.NewBuffer(data) + url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/note", accountID) + + if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil { + return fmt.Errorf("received an error after sending the request to set the private note; %w", err) + } + + return nil +}