From c7e612af26f1a52da95b90cd76adb4050e7e31d2 Mon Sep 17 00:00:00 2001 From: Romain Jeannoutot Date: Thu, 6 Oct 2022 15:03:42 +0200 Subject: [PATCH] feat(service): implement json marshal on user --- user.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/user.go b/user.go index 2f05932..1d00347 100644 --- a/user.go +++ b/user.go @@ -2,6 +2,7 @@ package visiauth import ( "context" + "encoding/json" "github.com/bitrise-io/go-utils/sliceutil" "golang.org/x/exp/maps" @@ -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(), + }) +}