Skip to content

Commit cfca2fc

Browse files
authored
Merge pull request #44 from mongodb/teamsProjects
Teams and projects resource were refactored due to issues
2 parents e6f2e30 + 3cc01da commit cfca2fc

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

mongodbatlas/projects.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ProjectsService interface {
3030
Create(context.Context, *Project) (*Project, *Response, error)
3131
Delete(context.Context, string) (*Response, error)
3232
GetProjectTeamsAssigned(context.Context, string) (*TeamsAssigned, *Response, error)
33-
AddTeamsToProject(context.Context, string, *ProjectTeam) (*TeamsAssigned, *Response, error)
33+
AddTeamsToProject(context.Context, string, []*ProjectTeam) (*TeamsAssigned, *Response, error)
3434
}
3535

3636
//ProjectsServiceOp handles communication with the Projects related methos of the
@@ -65,15 +65,10 @@ type Result struct {
6565
TeamID string `json:"teamId"`
6666
}
6767

68-
// RoleName represents the kind of user role in your project
69-
type RoleName struct {
70-
RoleName string `json:"rolesNames"`
71-
}
72-
7368
// ProjectTeam reperesents the kind of role that has the team
7469
type ProjectTeam struct {
75-
TeamID string `json:"teamId"`
76-
Roles []*RoleName `json:"roles"`
70+
TeamID string `json:"teamId,omitempty"`
71+
RoleNames []string `json:"roleNames,omitempty"`
7772
}
7873

7974
// TeamsAssigned represents the one team assigned to the project.
@@ -216,7 +211,7 @@ func (s *ProjectsServiceOp) GetProjectTeamsAssigned(ctx context.Context, project
216211

217212
//AddTeamsToProject adds teams to a project
218213
//See more: https://docs.atlas.mongodb.com/reference/api/project-add-team/
219-
func (s *ProjectsServiceOp) AddTeamsToProject(ctx context.Context, projectID string, createRequest *ProjectTeam) (*TeamsAssigned, *Response, error) {
214+
func (s *ProjectsServiceOp) AddTeamsToProject(ctx context.Context, projectID string, createRequest []*ProjectTeam) (*TeamsAssigned, *Response, error) {
220215
if createRequest == nil {
221216
return nil, nil, NewArgError("createRequest", "cannot be nil")
222217
}

mongodbatlas/projects_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,10 @@ func TestProject_AddTeamsToProject(t *testing.T) {
327327

328328
projectID := "5a0a1e7e0f2912c554080adc"
329329

330-
createRequest := &ProjectTeam{
331-
TeamID: "{TEAM-ID}",
332-
Roles: []*RoleName{
333-
{RoleName: GroupOwner},
334-
{RoleName: GroupReadOnly},
335-
},
336-
}
330+
createRequest := []*ProjectTeam{{
331+
TeamID: "{TEAM-ID}",
332+
RoleNames: []string{"GROUP_OWNER", "GROUP_READ_ONLY"},
333+
}}
337334

338335
mux.HandleFunc(fmt.Sprintf("/groups/%s/teams", projectID), func(w http.ResponseWriter, r *http.Request) {
339336
fmt.Fprint(w, `{

mongodbatlas/teams.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ func (s *TeamsServiceOp) UpdateTeamRoles(ctx context.Context, orgID string, team
230230
return nil, nil, NewArgError("updateTeamRolesRequest", "cannot be nil")
231231
}
232232

233-
basePath := fmt.Sprintf(teamsBasePath, orgID)
234-
path := fmt.Sprintf("%s/%s", basePath, teamID)
233+
path := fmt.Sprintf("groups/%s/teams/%s", orgID, teamID)
235234

236235
req, err := s.client.NewRequest(ctx, http.MethodPatch, path, updateTeamRolesRequest)
237236
if err != nil {

mongodbatlas/teams_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestTeams_UpdateTeamRoles(t *testing.T) {
344344

345345
teamID := "6b720e1087d9d66b272f1c86"
346346

347-
mux.HandleFunc(fmt.Sprintf("/orgs/%s/teams/%s", orgID, teamID), func(w http.ResponseWriter, r *http.Request) {
347+
mux.HandleFunc(fmt.Sprintf("/groups/%s/teams/%s", orgID, teamID), func(w http.ResponseWriter, r *http.Request) {
348348
expected := map[string]interface{}{
349349
"roleNames": []interface{}{"GROUP_OWNER"},
350350
}

0 commit comments

Comments
 (0)