Files

41 lines
1.1 KiB
Go

package sresponse
import (
customermodel "git.sendico.io/tech/sxchnge/product/customers/model"
"net/http"
"git.sendico.io/tech/sxchnge/shared/http/response"
"git.sendico.io/tech/sxchnge/shared/logging"
)
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 *customermodel.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 *customermodel.Account, accessToken *TokenData) http.HandlerFunc {
return response.Ok(
logger,
&accountResponse{
Account: *NewAccountData(account),
authResponse: authResponse{AccessToken: *accessToken},
},
)
}