gateway api: return user linked accounts

This commit is contained in:
Simone Gotti 2019-05-03 09:54:47 +02:00
parent 9349728997
commit b9db3137ad
1 changed files with 18 additions and 6 deletions

View File

@ -180,9 +180,14 @@ func (h *UserByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
type UserResponse struct { type UserResponse struct {
ID string `json:"id"` ID string `json:"id,omitempty"`
UserName string `json:"username"` UserName string `json:"username,omitempty"`
Tokens []string `json:"tokens"` Tokens []string `json:"tokens,omitempty"`
LinkedAccounts []*LinkedAccountResponse `json:"linked_accounts,omitempty"`
}
type LinkedAccountResponse struct {
RemoteSourceID string `json:"remote_source_id,omitempty"`
} }
func createUserResponse(u *types.User) *UserResponse { func createUserResponse(u *types.User) *UserResponse {
@ -190,12 +195,19 @@ func createUserResponse(u *types.User) *UserResponse {
ID: u.ID, ID: u.ID,
UserName: u.Name, UserName: u.Name,
Tokens: make([]string, 0, len(u.Tokens)), Tokens: make([]string, 0, len(u.Tokens)),
LinkedAccounts: make([]*LinkedAccountResponse, 0, len(u.LinkedAccounts)),
} }
for tokenName := range u.Tokens { for tokenName := range u.Tokens {
user.Tokens = append(user.Tokens, tokenName) user.Tokens = append(user.Tokens, tokenName)
} }
sort.Sort(sort.StringSlice(user.Tokens)) sort.Sort(sort.StringSlice(user.Tokens))
for _, la := range u.LinkedAccounts {
user.LinkedAccounts = append(user.LinkedAccounts, &LinkedAccountResponse{
RemoteSourceID: la.RemoteSourceID,
})
}
return user return user
} }