diff options
Diffstat (limited to 'backend/fortee/fortee.go')
| -rw-r--r-- | backend/fortee/fortee.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/backend/fortee/fortee.go b/backend/fortee/fortee.go index 5ec7963..79ba065 100644 --- a/backend/fortee/fortee.go +++ b/backend/fortee/fortee.go @@ -11,7 +11,8 @@ const ( ) var ( - ErrLoginFailed = errors.New("fortee login failed") + ErrLoginFailed = errors.New("fortee login failed") + ErrUserNotFound = errors.New("fortee user not found") ) func Login(ctx context.Context, username string, password string) (string, error) { @@ -39,6 +40,21 @@ func Login(ctx context.Context, username string, password string) (string, error return resOk.User.Username, nil } +func GetUserAvatarURL(ctx context.Context, username string) (string, error) { + client, err := NewClientWithResponses(apiEndpoint, WithRequestEditorFn(addAcceptHeader)) + if err != nil { + return "", err + } + res, err := client.GetUserWithResponse(ctx, username) + if err != nil { + return "", err + } + if res.StatusCode() != http.StatusOK { + return "", ErrUserNotFound + } + return res.JSON200.AvatarURL, nil +} + // fortee API denies requests without Accept header. func addAcceptHeader(_ context.Context, req *http.Request) error { req.Header.Set("Accept", "application/json") |
