-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from ctreminiom/feature/teams-service
✨ Added the Jira Roadmaps Team service
- Loading branch information
Showing
8 changed files
with
511 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
model "github.com/ctreminiom/go-atlassian/pkg/infra/models" | ||
"github.com/ctreminiom/go-atlassian/service" | ||
"github.com/ctreminiom/go-atlassian/service/jira" | ||
"net/http" | ||
) | ||
|
||
func NewTeamService(client service.Client) *TeamService { | ||
|
||
return &TeamService{ | ||
internalClient: &internalTeamServiceImpl{c: client}, | ||
} | ||
} | ||
|
||
type TeamService struct { | ||
internalClient jira.TeamConnector | ||
} | ||
|
||
// Gets gets the Teams information from the Jira Advanced Roadmaps application. | ||
// | ||
// Teams in Advanced Roadmaps are different from the teams found in the rest of Jira Software Cloud. | ||
// | ||
// In Advanced Roadmaps, they act as a label applied to issues that designates which team will eventually. | ||
// | ||
// pick up the work on your timeline. By adding the Team field to your Jira issues. | ||
// | ||
// you can save this value back to your Jira issues, which makes sprint planning easier. | ||
// | ||
// POST /rest/teams/1.0/teams/find | ||
// | ||
// https://docs.go-atlassian.io/jira-software-cloud/teams#get-teams | ||
func (t *TeamService) Gets(ctx context.Context, maxResults int) (*model.JiraTeamPageScheme, *model.ResponseScheme, error) { | ||
return t.internalClient.Gets(ctx, maxResults) | ||
} | ||
|
||
// Create creates a team on the Advanced Roadmaps | ||
// | ||
// POST /rest/teams/1.0/teams/create | ||
// | ||
// https://docs.go-atlassian.io/jira-software-cloud/teams#create-team | ||
func (t *TeamService) Create(ctx context.Context, payload *model.JiraTeamCreatePayloadScheme) (*model.JiraTeamCreateResponseScheme, *model.ResponseScheme, error) { | ||
return t.internalClient.Create(ctx, payload) | ||
} | ||
|
||
type internalTeamServiceImpl struct { | ||
c service.Client | ||
} | ||
|
||
func (i *internalTeamServiceImpl) Gets(ctx context.Context, maxResults int) (*model.JiraTeamPageScheme, *model.ResponseScheme, error) { | ||
|
||
payload := struct { | ||
MaxResults int `json:"maxResults"` | ||
}{ | ||
MaxResults: maxResults, | ||
} | ||
|
||
reader, err := i.c.TransformStructToReader(&payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
endpoint := "rest/teams/1.0/teams/find" | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodPost, endpoint, reader) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
teams := new(model.JiraTeamPageScheme) | ||
response, err := i.c.Call(request, teams) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return teams, response, nil | ||
} | ||
|
||
func (i *internalTeamServiceImpl) Create(ctx context.Context, payload *model.JiraTeamCreatePayloadScheme) (*model.JiraTeamCreateResponseScheme, *model.ResponseScheme, error) { | ||
|
||
reader, err := i.c.TransformStructToReader(payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
endpoint := "rest/teams/1.0/teams/create" | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodPost, endpoint, reader) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
team := new(model.JiraTeamCreateResponseScheme) | ||
response, err := i.c.Call(request, team) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return team, response, nil | ||
} |
Oops, something went wrong.