Skip to content

Commit

Permalink
Only expose props we need from usergroup list to initial state (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
auggod authored Oct 14, 2023
1 parent 43b0b85 commit 909c2d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
11 changes: 10 additions & 1 deletion web/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@ func (s *Service) authorizeForm(w http.ResponseWriter, r *http.Request) {
string(initialState),
)

var usergroupList []UserGroup

for i := range usergroups.Usergroup {
usergroupList = append(usergroupList, UserGroup{
ID: usergroups.Usergroup[i].ID,
DisplayName: usergroups.Usergroup[i].DisplayName,
})
}

profile := &Profile{
Email: user.Username,
EmailConfirmed: user.EmailConfirmed,
LegacyID: user.LegacyID,
Complete: isUserAccountComplete,
Usergroups: usergroups.Usergroup,
Usergroups: usergroupList,
}

if len(usergroups.Usergroup) > 0 {
Expand Down
11 changes: 10 additions & 1 deletion web/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,22 @@ func (s *Service) checkoutForm(w http.ResponseWriter, r *http.Request) {
string(initialState),
)

var usergroupList []UserGroup

for i := range usergroups.Usergroup {
usergroupList = append(usergroupList, UserGroup{
ID: usergroups.Usergroup[i].ID,
DisplayName: usergroups.Usergroup[i].DisplayName,
})
}

profile := &Profile{
Email: user.Username,
LegacyID: user.LegacyID,
Country: user.Country,
EmailConfirmed: user.EmailConfirmed,
Complete: isUserAccountComplete,
Usergroups: usergroups.Usergroup,
Usergroups: usergroupList,
}

if len(usergroups.Usergroup) > 0 {
Expand Down
29 changes: 22 additions & 7 deletions web/initial_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/resonatecoop/user-api/model"
)

// Usergroup public
type UserGroup struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
}

// Profile user public profile
type Profile struct {
ID string `json:"id"`
Expand All @@ -18,12 +24,12 @@ type Profile struct {
// FullName string `json:"fullName"`
// FirstName string `json:"firstName"`
// LastName string `json:"lastName"`
Country string `json:"country"`
NewsletterNotification bool `json:"newsletterNotification"`
EmailConfirmed bool `json:"emailConfirmed"`
Member bool `json:"member"`
Complete bool `json:"complete"`
Usergroups []*models.UserUserGroupPrivateResponse `json:"usergroups"`
Country string `json:"country"`
NewsletterNotification bool `json:"newsletterNotification"`
EmailConfirmed bool `json:"emailConfirmed"`
Member bool `json:"member"`
Complete bool `json:"complete"`
Usergroups []UserGroup `json:"usergroups"`
}

// NewProfile
Expand All @@ -40,6 +46,15 @@ func NewProfile(
displayName = usergroups[0].DisplayName
}

var usergroupList []UserGroup

for i := range usergroups {
usergroupList = append(usergroupList, UserGroup{
ID: usergroups[i].ID,
DisplayName: usergroups[i].DisplayName,
})
}

return &Profile{
ID: user.ID.String(),
Complete: isUserAccountComplete,
Expand All @@ -52,7 +67,7 @@ func NewProfile(
LegacyID: user.LegacyID,
Member: user.Member,
NewsletterNotification: user.NewsletterNotification,
Usergroups: usergroups,
Usergroups: usergroupList,
}
}

Expand Down

0 comments on commit 909c2d8

Please sign in to comment.