From 358d5fdf6092f485ead62dbb2330053c6768964d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 14 Mar 2024 06:42:38 -0400 Subject: [PATCH] feat: add account info endpoint --- api/account/account.go | 15 +++++++++++++++ api/account/messages.go | 6 ++++++ api/account/swagger.yaml | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/api/account/account.go b/api/account/account.go index d9491b9..bf8fc12 100644 --- a/api/account/account.go +++ b/api/account/account.go @@ -270,6 +270,20 @@ func (a AccountAPI) ping(jc jape.Context) { }) } +func (a AccountAPI) accountInfo(jc jape.Context) { + user := middleware.GetUserFromContext(jc.Request.Context()) + + _, acct, _ := a.accounts.AccountExists(user) + + jc.Encode(&AccountInfoResponse{ + ID: acct.ID, + Email: acct.Email, + FirstName: acct.FirstName, + LastName: acct.LastName, + }) + +} + func (a AccountAPI) Routes() (*httprouter.Router, error) { loginAuthMw2fa := authMiddleware(middleware.AuthMiddlewareOptions{ Identity: a.identity, @@ -304,6 +318,7 @@ func (a AccountAPI) Routes() (*httprouter.Router, error) { "POST /api/auth/otp/disable": middleware.ApplyMiddlewares(a.otpDisable, authMw, middleware.ProxyMiddleware), "POST /api/auth/password-reset/request": middleware.ApplyMiddlewares(a.passwordResetRequest, middleware.ProxyMiddleware), "POST /api/auth/password-reset/confirm": middleware.ApplyMiddlewares(a.passwordResetConfirm, middleware.ProxyMiddleware), + "GET /api/account": middleware.ApplyMiddlewares(a.accountInfo, authMw, middleware.ProxyMiddleware), } routes, err := swagger.Swagger(swagSpec, routes) diff --git a/api/account/messages.go b/api/account/messages.go index 4a2a0b3..fcc96db 100644 --- a/api/account/messages.go +++ b/api/account/messages.go @@ -46,3 +46,9 @@ type PasswordResetVerifyRequest struct { type PongResponse struct { Ping string `json:"ping"` } +type AccountInfoResponse struct { + ID uint `json:"id"` + Email string `json:"email"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` +} diff --git a/api/account/swagger.yaml b/api/account/swagger.yaml index edd47ca..3e9f96e 100644 --- a/api/account/swagger.yaml +++ b/api/account/swagger.yaml @@ -130,6 +130,18 @@ paths: $ref: '#/components/schemas/PingResponse' '401': description: Unauthorized + /api/account: + get: + summary: Get account information + responses: + '200': + description: Account information retrieved successfully + content: + application/json: + schema: + $ref: '#/components/schemas/AccountInfoResponse' + '401': + description: Unauthorized components: schemas: @@ -225,3 +237,14 @@ components: properties: ping: type: string + AccountInfoResponse: + type: object + properties: + id: + type: number + first_name: + type: string + last_name: + type: string + email: + type: string