Add account fetch endpoint
This commit is contained in:
parent
3ed41590c7
commit
9b2f52c4a4
33
internal/router/api/v1/account/fetch.go
Normal file
33
internal/router/api/v1/account/fetch.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.supernets.org/perp/gopay/internal/context"
|
||||||
|
v1 "git.supernets.org/perp/gopay/internal/models/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// @summary Fetch an account
|
||||||
|
// @tags account
|
||||||
|
// @accept json
|
||||||
|
// @produce json
|
||||||
|
// @success 200 {object} v1.Account
|
||||||
|
// @response default {object} v1.Error "There was an error"
|
||||||
|
// @router /v1/account [get]
|
||||||
|
func Fetch(ctx *context.Context) {
|
||||||
|
// Call middleware
|
||||||
|
ctx.GetAccount()
|
||||||
|
|
||||||
|
// Account not found
|
||||||
|
if ctx.Account == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create information
|
||||||
|
information := &v1.Account{
|
||||||
|
ID: ctx.Account.ID,
|
||||||
|
Username: ctx.Account.Username,
|
||||||
|
Admin: ctx.Account.Admin,
|
||||||
|
Created: ctx.Account.Created.Unix(),
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, information)
|
||||||
|
}
|
@ -26,6 +26,7 @@ func Register(ctx *context.Context, engine *gin.Engine) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
a := v1.Group("account")
|
a := v1.Group("account")
|
||||||
|
a.GET("", ctx.Register(account.Fetch))
|
||||||
a.POST("login", ctx.Register(account.Login))
|
a.POST("login", ctx.Register(account.Login))
|
||||||
a.POST("register", ctx.Register(account.Register))
|
a.POST("register", ctx.Register(account.Register))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user