41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package sresponse
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/api/http/response"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/mlogger"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/model"
|
|
)
|
|
|
|
type AccountData struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
LastName string `json:"lastName"`
|
|
Login string `json:"login"`
|
|
Locale string `json:"locale"`
|
|
AvatarURL *string `json:"avatarUrl,omitempty"`
|
|
}
|
|
|
|
type accountResponse struct {
|
|
authResponse `json:",inline"`
|
|
Account AccountData `json:"account"`
|
|
}
|
|
|
|
func NewAccountData(account *model.Account) *AccountData {
|
|
return &AccountData{
|
|
ID: account.ID.Hex(), Name: account.Name, LastName: account.LastName,
|
|
Login: account.Login, Locale: account.Locale, AvatarURL: account.AvatarURL,
|
|
}
|
|
}
|
|
|
|
func Account(logger mlogger.Logger, account *model.Account, accessToken *TokenData) http.HandlerFunc {
|
|
return response.Ok(
|
|
logger,
|
|
&accountResponse{
|
|
Account: *NewAccountData(account),
|
|
authResponse: authResponse{AccessToken: *accessToken},
|
|
},
|
|
)
|
|
}
|