Skip to content

Commit

Permalink
wrap organizations members into a object
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Sep 30, 2024
1 parent ad170ff commit bf16dd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 9 additions & 6 deletions api/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [🆕 Create organization](#-create-organization)
- [⚙️ Update organization](#-update-organization)
- [🔍 Organization info](#-organization-info)
- [🧑‍🤝‍🧑 Organization members](#-organization-members)

</details>

Expand Down Expand Up @@ -545,12 +546,14 @@ Only the following parameters can be changed. Every parameter is optional.
* **Method** `GET`
* **Response**
```json
[
{
"info": { /* user info response */ },
"role": "admin"
}
]
{
"members": [
{
"info": { /* user info response */ },
"role": "admin"
}
]
}
```

* **Errors**
Expand Down
6 changes: 4 additions & 2 deletions api/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func (a *API) organizationMembersHandler(w http.ResponseWriter, r *http.Request)
ErrGenericInternalServerError.Withf("could not get organization members: %v", err).Write(w)
return
}
orgMembers := []OrganizationMember{}
orgMembers := OrganizationMembers{
Members: make([]*OrganizationMember, 0, len(members)),
}
for _, member := range members {
var role string
for _, userOrg := range member.Organizations {
Expand All @@ -134,7 +136,7 @@ func (a *API) organizationMembersHandler(w http.ResponseWriter, r *http.Request)
if role == "" {
continue
}
orgMembers = append(orgMembers, OrganizationMember{
orgMembers.Members = append(orgMembers.Members, &OrganizationMember{
Info: &UserInfo{
Email: member.Email,
FirstName: member.FirstName,
Expand Down
6 changes: 6 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ type OrganizationInfo struct {
Parent *OrganizationInfo `json:"parent"`
}

// OrganizationMembers is the struct that represents a list of members of
// organizations in the API.
type OrganizationMembers struct {
Members []*OrganizationMember `json:"members"`
}

// OrganizationMember is the struct that represents a members of organizations
// with his role in the API.
type OrganizationMember struct {
Expand Down

0 comments on commit bf16dd3

Please sign in to comment.