From 721b8e0d0652daf84d947cb9cab65e29b4b88f76 Mon Sep 17 00:00:00 2001 From: Obaro Ikoh Date: Thu, 25 Feb 2021 21:29:28 +0100 Subject: [PATCH] Update profile by username --- affiliation/dto.go | 5 +++++ affiliation/identity.go | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/affiliation/dto.go b/affiliation/dto.go index 1deb95f..c8484bc 100644 --- a/affiliation/dto.go +++ b/affiliation/dto.go @@ -113,3 +113,8 @@ type AffIdentity struct { IsBot *int64 `json:"is_bot"` MultiOrgNames []string `json:"multi_org_names"` } + +// ProfileByUsernameResponse ... +type ProfileByUsernameResponse struct { + Profiles []ProfileResponse `json:"profiles"` +} diff --git a/affiliation/identity.go b/affiliation/identity.go index 06236ee..cdc65b2 100644 --- a/affiliation/identity.go +++ b/affiliation/identity.go @@ -307,26 +307,29 @@ func (a *Affiliation) GetProfileByUsername(username string, projectSlug string) return nil, errors.New("User not found") } - var profile UniqueIdentityFullProfile - err = json.Unmarshal(res, &profile) + var profiles ProfileByUsernameResponse + err = json.Unmarshal(res, &profiles) if err != nil { return nil, err } + + profile := profiles.Profiles[0] + var identity AffIdentity profileIdentity := profile.Identities[0] - identity.UUID = profileIdentity.UUID + identity.UUID = &profileIdentity.UUID - if profileIdentity.Name != nil { - identity.Name = *profileIdentity.Name + if profileIdentity.Name != "" { + identity.Name = profileIdentity.Name } else { identity.Name = unknown } identity.Username = username - if profileIdentity.Email != nil { - identity.Email = *profileIdentity.Email + if profileIdentity.Email != "" { + identity.Email = profileIdentity.Email } identity.ID = &profileIdentity.ID @@ -360,7 +363,7 @@ func (a *Affiliation) GetProfileByUsername(username string, projectSlug string) } // Get Most Recent Org Name where user has multiple enrollments -func (a *Affiliation) getUserOrg(enrollments []*Enrollments) *string { +func (a *Affiliation) getUserOrg(enrollments []Enrollment) *string { var result string var lowest, startTime int64 now := time.Now()