aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/fortee/fortee.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-17 19:46:36 +0900
committernsfisis <nsfisis@gmail.com>2024-08-17 19:46:43 +0900
commit48a70e06f54d81cdc6b0c22c2dcce8426b86decf (patch)
tree0e737357a174e564e182e41461f163af08356d23 /backend/fortee/fortee.go
parent34592a45efd9ceb0579c8eae1ba752da7f625950 (diff)
downloadphperkaigi-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.go18
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")