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" "go.mongodb.org/mongo-driver/v2/bson" ) type AccountData struct { model.AccountPublic `json:",inline"` IsAnonymous bool `json:"isAnonymous"` } type accountResponse struct { authResponse `json:",inline"` Account AccountData `json:"account"` } type accountsResponse struct { authResponse `json:",inline"` Accounts []AccountData `json:"accounts"` } func NewAccountData(account *model.Account, isAnonymous bool) *AccountData { return &AccountData{ AccountPublic: account.AccountPublic, IsAnonymous: isAnonymous, } } func Account(logger mlogger.Logger, account *model.Account, accessToken *TokenData) http.HandlerFunc { return response.Ok( logger, &accountResponse{ Account: *NewAccountData(account, false), authResponse: authResponse{AccessToken: *accessToken}, }, ) } func Accounts(logger mlogger.Logger, accounts []model.Account, orgRef bson.ObjectID, accessToken *TokenData) http.HandlerFunc { publicAccounts := make([]AccountData, len(accounts)) for i := range accounts { publicAccounts[i] = *NewAccountData( &accounts[i], model.AccountIsAnonymous(&accounts[i].UserDataBase, orgRef), ) } return response.Ok( logger, &accountsResponse{ Accounts: publicAccounts, authResponse: authResponse{AccessToken: *accessToken}, }, ) }