diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-17 19:46:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-17 19:46:43 +0900 |
| commit | 48a70e06f54d81cdc6b0c22c2dcce8426b86decf (patch) | |
| tree | 0e737357a174e564e182e41461f163af08356d23 /backend/fortee/fortee.go | |
| parent | 34592a45efd9ceb0579c8eae1ba752da7f625950 (diff) | |
| download | phperkaigi-2025-albatross-48a70e06f54d81cdc6b0c22c2dcce8426b86decf.tar.gz phperkaigi-2025-albatross-48a70e06f54d81cdc6b0c22c2dcce8426b86decf.tar.zst phperkaigi-2025-albatross-48a70e06f54d81cdc6b0c22c2dcce8426b86decf.zip | |
feat(backend): add API definition of fortee user get
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") |
