Skip to content

Commit

Permalink
feat(service): implement json marshal on user
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-jeannoutot committed Oct 6, 2022
1 parent 0dcb2fb commit c7e612a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package visiauth

import (
"context"
"encoding/json"

"github.com/bitrise-io/go-utils/sliceutil"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -84,3 +85,19 @@ func (u User) HighestRoleInOrganizations() map[string]string {
func (u User) HighestRoleInOrganization(organizationId string) string {
return u.organizationsRole[organizationId]
}

func (u User) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
ID string `json:"id"`
LegacyID string `json:"legacyId"`
Scopes []string `json:"scopes"`
OrganizationsRole map[string][]string `json:"organizationsRole"`
OrganizationLegacyIDs []string `json:"organizationLegacyIds"`
}{
ID: u.ID(),
LegacyID: u.LegacyID(),
Scopes: u.Scopes(),
OrganizationsRole: u.OrganizationRoles(),
OrganizationLegacyIDs: u.OrganizationLegacyIds(),
})
}

0 comments on commit c7e612a

Please sign in to comment.