4
4
"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
5
5
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
6
6
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
7
+ "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
7
8
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
8
9
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
9
10
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services/api"
@@ -25,6 +26,8 @@ func NewTeamService(sling *sling.Sling, uriTemplate string) *TeamService {
25
26
}
26
27
27
28
// Add creates a new team.
29
+ //
30
+ // Deprecated: use teams.Add()
28
31
func (s * TeamService ) Add (team * Team ) (* Team , error ) {
29
32
if IsNil (team ) {
30
33
return nil , internal .CreateInvalidParameterError (constants .OperationAdd , constants .ParameterTeam )
@@ -46,6 +49,8 @@ func (s *TeamService) Add(team *Team) (*Team, error) {
46
49
// Delete will delete a team if it is not a built-in team (i.e. the field,
47
50
// CanBeDeleted is true). If the team cannot be deleted or an error occurs, it
48
51
// returns an error.
52
+ //
53
+ // Deprecated: use teams.Delete()
49
54
func (s * TeamService ) Delete (team * Team ) error {
50
55
if team == nil {
51
56
return internal .CreateInvalidParameterError (constants .OperationDelete , constants .ParameterTeam )
@@ -62,6 +67,8 @@ func (s *TeamService) Delete(team *Team) error {
62
67
// Get returns a collection of teams based on the criteria defined by its input
63
68
// query parameter. If an error occurs, an empty collection is returned along
64
69
// with the associated error.
70
+ //
71
+ // Deprecated: use teams.Get()
65
72
func (s * TeamService ) Get (teamsQuery TeamsQuery ) (* resources.Resources [* Team ], error ) {
66
73
path , err := s .GetURITemplate ().Expand (teamsQuery )
67
74
if err != nil {
@@ -78,6 +85,8 @@ func (s *TeamService) Get(teamsQuery TeamsQuery) (*resources.Resources[*Team], e
78
85
79
86
// GetAll returns all teams. If none can be found or an error occurs, it
80
87
// returns an empty collection.
88
+ //
89
+ // Deprecated: use teams.GetAll()
81
90
func (s * TeamService ) GetAll () ([]* Team , error ) {
82
91
items := []* Team {}
83
92
path , err := services .GetAllPath (s )
@@ -91,6 +100,8 @@ func (s *TeamService) GetAll() ([]*Team, error) {
91
100
92
101
// GetByID returns the team that matches the input ID. If one cannot be found,
93
102
// it returns nil and an error.
103
+ //
104
+ // Deprecated: use teams.GetById()
94
105
func (s * TeamService ) GetByID (id string ) (* Team , error ) {
95
106
if internal .IsEmpty (id ) {
96
107
return nil , internal .CreateInvalidParameterError (constants .OperationGetByID , constants .ParameterID )
@@ -125,6 +136,8 @@ func (s *TeamService) GetByPartialName(partialName string) ([]*Team, error) {
125
136
}
126
137
127
138
// Update modifies a team based on the one provided as input.
139
+ //
140
+ // Deprecated: use teams.Update()
128
141
func (s * TeamService ) Update (team * Team ) (* Team , error ) {
129
142
path , err := services .GetUpdatePath (s , team )
130
143
if err != nil {
@@ -150,3 +163,69 @@ func (s *TeamService) GetScopedUserRoles(team Team, query core.SkipTakeQuery) (*
150
163
151
164
return resp .(* resources.Resources [* userroles.ScopedUserRole ]), nil
152
165
}
166
+
167
+ // --- new ---
168
+
169
+ const template = "/api/{spaceId}/teams{/id}{?skip,take,ids,partialName}"
170
+ const scopedUserRolesTemplate = "/api/teams{/id}/scopeduserroles"
171
+
172
+ // Add creates a new team.
173
+ func Add (client newclient.Client , team * Team ) (* Team , error ) {
174
+ return newclient .Add [Team ](client , template , team .SpaceID , team )
175
+ }
176
+
177
+ // Get returns a collection of teams based on the criteria defined by its
178
+ // input query parameter.
179
+ func Get (client newclient.Client , spaceID string , teamsQuery TeamsQuery ) (* resources.Resources [* Team ], error ) {
180
+ return newclient .GetByQuery [Team ](client , template , spaceID , teamsQuery )
181
+ }
182
+
183
+ // GetByID returns the team that matches the input ID.
184
+ func GetByID (client newclient.Client , spaceID string , ID string ) (* Team , error ) {
185
+ return newclient .GetByID [Team ](client , template , spaceID , ID )
186
+ }
187
+
188
+ // Update modifies a team based on the one provided as input.
189
+ func Update (client newclient.Client , team * Team ) (* Team , error ) {
190
+ return newclient .Update [Team ](client , template , team .SpaceID , team .ID , team )
191
+ }
192
+
193
+ // GetAll returns all teams. If an error occurs, it returns nil.
194
+ func GetAll (client newclient.Client , spaceID string ) ([]* Team , error ) {
195
+ return newclient .GetAll [Team ](client , template , spaceID )
196
+ }
197
+
198
+ // Delete will delete a team if it is not a built-in team (i.e. the field,
199
+ // CanBeDeleted is true). If the team cannot be deleted or an error occurs, it
200
+ // returns an error.
201
+ func Delete (client newclient.Client , team * Team ) error {
202
+ if team == nil {
203
+ return internal .CreateInvalidParameterError (constants .OperationDelete , constants .ParameterTeam )
204
+ }
205
+
206
+ if ! team .CanBeDeleted {
207
+ return internal .CreateBuiltInTeamsCannotDeleteError ()
208
+ }
209
+
210
+ return newclient .DeleteByID (client , template , team .SpaceID , team .ID )
211
+ }
212
+
213
+ // func GetScopedUserRoles(client newclient.Client, team *Team, query core.SkipTakeQuery) (*[]*userroles.ScopedUserRole, error) {
214
+ // values, _ := uritemplates.Struct2map(query)
215
+ // if values == nil {
216
+ // values = map[string]any{}
217
+ // }
218
+
219
+ // values["id"] = team.ID
220
+ // path, err := client.URITemplateCache().Expand(scopedUserRolesTemplate, values)
221
+ // if err != nil {
222
+ // return nil, err
223
+ // }
224
+
225
+ // res, err := newclient.Get[[]*userroles.ScopedUserRole](client.HttpSession(), path)
226
+ // if err != nil {
227
+ // return nil, err
228
+ // }
229
+
230
+ // return res, nil
231
+ // }
0 commit comments