feat: add account info endpoint

This commit is contained in:
Derrick Hammer 2024-03-14 06:42:38 -04:00
parent d946e969bc
commit 358d5fdf60
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 44 additions and 0 deletions

View File

@ -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)

View File

@ -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"`
}

View File

@ -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