feat: add account info endpoint
This commit is contained in:
parent
d946e969bc
commit
358d5fdf60
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue