Skip to content

Commit 85d8f82

Browse files
Adding projectOwnerId to Projects.Create (#251)
1 parent a40fdd6 commit 85d8f82

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

mongodbatlas/projects.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ProjectsService interface {
4242
GetAllProjects(context.Context, *ListOptions) (*Projects, *Response, error)
4343
GetOneProject(context.Context, string) (*Project, *Response, error)
4444
GetOneProjectByName(context.Context, string) (*Project, *Response, error)
45-
Create(context.Context, *Project) (*Project, *Response, error)
45+
Create(context.Context, *Project, *CreateProjectOptions) (*Project, *Response, error)
4646
Delete(context.Context, string) (*Response, error)
4747
GetProjectTeamsAssigned(context.Context, string) (*TeamsAssigned, *Response, error)
4848
AddTeamsToProject(context.Context, string, []*ProjectTeam) (*TeamsAssigned, *Response, error)
@@ -99,6 +99,10 @@ type TeamsAssigned struct {
9999
TotalCount int `json:"totalCount"`
100100
}
101101

102+
type CreateProjectOptions struct {
103+
ProjectOwnerID string `url:"projectOwnerId,omitempty"` // Unique 24-hexadecimal digit string that identifies the Atlas user account to be granted the Project Owner role on the specified project.
104+
}
105+
102106
// GetAllProjects gets all project.
103107
//
104108
// See more: https://docs.atlas.mongodb.com/reference/api/project-get-all/
@@ -177,12 +181,17 @@ func (s *ProjectsServiceOp) GetOneProjectByName(ctx context.Context, projectName
177181
// Create creates a project.
178182
//
179183
// See more: https://docs.atlas.mongodb.com/reference/api/project-create-one/
180-
func (s *ProjectsServiceOp) Create(ctx context.Context, createRequest *Project) (*Project, *Response, error) {
184+
func (s *ProjectsServiceOp) Create(ctx context.Context, createRequest *Project, opts *CreateProjectOptions) (*Project, *Response, error) {
181185
if createRequest == nil {
182186
return nil, nil, NewArgError("createRequest", "cannot be nil")
183187
}
184188

185-
req, err := s.Client.NewRequest(ctx, http.MethodPost, projectBasePath, createRequest)
189+
path, err := setListOptions(projectBasePath, opts)
190+
if err != nil {
191+
return nil, nil, err
192+
}
193+
194+
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, createRequest)
186195
if err != nil {
187196
return nil, nil, err
188197
}

mongodbatlas/projects_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,56 @@ func TestProject_Create(t *testing.T) {
219219
}`)
220220
})
221221

222-
project, _, err := client.Projects.Create(ctx, createRequest)
222+
opts := &CreateProjectOptions{ProjectOwnerID: "1"}
223+
224+
project, _, err := client.Projects.Create(ctx, createRequest, opts)
225+
if err != nil {
226+
t.Fatalf("Projects.Create returned error: %v", err)
227+
}
228+
229+
expected := &Project{
230+
ClusterCount: 2,
231+
Created: "2016-07-14T14:19:33Z",
232+
ID: "5a0a1e7e0f2912c554080ae6",
233+
Links: []*Link{
234+
{
235+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/5a0a1e7e0f2912c554080ae6",
236+
Rel: "self",
237+
},
238+
},
239+
Name: "ProjectFoobar",
240+
OrgID: "5a0a1e7e0f2912c554080adc",
241+
}
242+
243+
if diff := deep.Equal(project, expected); diff != nil {
244+
t.Error(diff)
245+
}
246+
}
247+
248+
func TestProject_Create_without_opts(t *testing.T) {
249+
client, mux, teardown := setup()
250+
defer teardown()
251+
252+
createRequest := &Project{
253+
OrgID: "5a0a1e7e0f2912c554080adc",
254+
Name: "ProjectFoobar",
255+
}
256+
257+
mux.HandleFunc("/api/atlas/v1.0/groups", func(w http.ResponseWriter, r *http.Request) {
258+
fmt.Fprint(w, `{
259+
"clusterCount": 2,
260+
"created": "2016-07-14T14:19:33Z",
261+
"id": "5a0a1e7e0f2912c554080ae6",
262+
"links": [{
263+
"href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/5a0a1e7e0f2912c554080ae6",
264+
"rel": "self"
265+
}],
266+
"name": "ProjectFoobar",
267+
"orgId": "5a0a1e7e0f2912c554080adc"
268+
}`)
269+
})
270+
271+
project, _, err := client.Projects.Create(ctx, createRequest, nil)
223272
if err != nil {
224273
t.Fatalf("Projects.Create returned error: %v", err)
225274
}

0 commit comments

Comments
 (0)