44 "github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
55 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
66 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
7+ "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
78 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
89 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
910 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services/api"
@@ -25,6 +26,8 @@ func NewTeamService(sling *sling.Sling, uriTemplate string) *TeamService {
2526}
2627
2728// Add creates a new team.
29+ //
30+ // Deprecated: use teams.Add()
2831func (s * TeamService ) Add (team * Team ) (* Team , error ) {
2932 if IsNil (team ) {
3033 return nil , internal .CreateInvalidParameterError (constants .OperationAdd , constants .ParameterTeam )
@@ -46,6 +49,8 @@ func (s *TeamService) Add(team *Team) (*Team, error) {
4649// Delete will delete a team if it is not a built-in team (i.e. the field,
4750// CanBeDeleted is true). If the team cannot be deleted or an error occurs, it
4851// returns an error.
52+ //
53+ // Deprecated: use teams.Delete()
4954func (s * TeamService ) Delete (team * Team ) error {
5055 if team == nil {
5156 return internal .CreateInvalidParameterError (constants .OperationDelete , constants .ParameterTeam )
@@ -62,6 +67,8 @@ func (s *TeamService) Delete(team *Team) error {
6267// Get returns a collection of teams based on the criteria defined by its input
6368// query parameter. If an error occurs, an empty collection is returned along
6469// with the associated error.
70+ //
71+ // Deprecated: use teams.Get()
6572func (s * TeamService ) Get (teamsQuery TeamsQuery ) (* resources.Resources [* Team ], error ) {
6673 path , err := s .GetURITemplate ().Expand (teamsQuery )
6774 if err != nil {
@@ -78,6 +85,8 @@ func (s *TeamService) Get(teamsQuery TeamsQuery) (*resources.Resources[*Team], e
7885
7986// GetAll returns all teams. If none can be found or an error occurs, it
8087// returns an empty collection.
88+ //
89+ // Deprecated: use teams.GetAll()
8190func (s * TeamService ) GetAll () ([]* Team , error ) {
8291 items := []* Team {}
8392 path , err := services .GetAllPath (s )
@@ -91,6 +100,8 @@ func (s *TeamService) GetAll() ([]*Team, error) {
91100
92101// GetByID returns the team that matches the input ID. If one cannot be found,
93102// it returns nil and an error.
103+ //
104+ // Deprecated: use teams.GetById()
94105func (s * TeamService ) GetByID (id string ) (* Team , error ) {
95106 if internal .IsEmpty (id ) {
96107 return nil , internal .CreateInvalidParameterError (constants .OperationGetByID , constants .ParameterID )
@@ -125,6 +136,8 @@ func (s *TeamService) GetByPartialName(partialName string) ([]*Team, error) {
125136}
126137
127138// Update modifies a team based on the one provided as input.
139+ //
140+ // Deprecated: use teams.Update()
128141func (s * TeamService ) Update (team * Team ) (* Team , error ) {
129142 path , err := services .GetUpdatePath (s , team )
130143 if err != nil {
@@ -150,3 +163,69 @@ func (s *TeamService) GetScopedUserRoles(team Team, query core.SkipTakeQuery) (*
150163
151164 return resp .(* resources.Resources [* userroles.ScopedUserRole ]), nil
152165}
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