Skip to content

Commit

Permalink
Alignments
Browse files Browse the repository at this point in the history
  * function struct inputs shall be pointers
  * RequestService.MakeURL improved with slice handling
  • Loading branch information
theriverman committed May 19, 2020
1 parent 0639e5d commit 95d1aca
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions common.functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
*/

// listAttachmentsForEndpoint is a common method to get attachments for an endpoint (userstories, tasks, etc...)
func listAttachmentsForEndpoint(c *Client, queryParams *attachmentsQueryParams) (*[]Attachment, error) {
func listAttachmentsForEndpoint(c *Client, queryParams *attachmentsQueryParams) ([]Attachment, error) {
paramValues, _ := query.Values(queryParams)
url := c.APIURL + queryParams.endpointURI + "/attachments?" + paramValues.Encode()
var attachmentsList []Attachment
Expand All @@ -23,7 +23,7 @@ func listAttachmentsForEndpoint(c *Client, queryParams *attachmentsQueryParams)
if err != nil {
return nil, err
}
return &attachmentsList, nil
return attachmentsList, nil
}

// getAttachmentForEndpoint is a common method to get a specific attachment for an endpoint (epic, issue, etc...)
Expand Down
12 changes: 5 additions & 7 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ type RequestService struct {
// MakeURL accepts an Endpoint URL and returns a compiled absolute URL
//
// For example:
// * If the given endpoint URL is /epic-custom-attributes
// * If the given endpoint URLs are [epics, attachments]
// * If the BaseURL is https://api.taiga.io
// * It returns https://api.taiga.io/api/v1/epic-custom-attributes
func (s *RequestService) MakeURL(Endpoint string) string {
if strings.HasPrefix(Endpoint, "/") {
return s.client.APIURL + Endpoint
}
return s.client.APIURL + "/" + Endpoint
// * It returns https://api.taiga.io/api/v1/epics/attachments
// * Suffixes are appended to the URL joined by a slash (/)
func (s *RequestService) MakeURL(EndpointParts ...string) string {
return s.client.APIURL + "/" + strings.Join(EndpointParts, "/")
}

// SuccessfulHTTPRequest returns true if the given Response's StatusCode
Expand Down
6 changes: 2 additions & 4 deletions stats.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package taigo

import "fmt"

var statsURI = "/stats"

// StatsService is a handle to Stats operations
Expand All @@ -12,7 +10,7 @@ type StatsService struct {

// GetDiscoverStats => https://taigaio.github.io/taiga-doc/dist/api.html#discover-stats
func (s *StatsService) GetDiscoverStats() (*DiscoverStats, error) {
url := s.client.Request.MakeURL(fmt.Sprintf("%s/discover", statsURI))
url := s.client.Request.MakeURL(statsURI, "discover")
var respDiscoverStats DiscoverStats
err := s.client.Request.GetRequest(url, &respDiscoverStats)
if err != nil {
Expand All @@ -23,7 +21,7 @@ func (s *StatsService) GetDiscoverStats() (*DiscoverStats, error) {

// GetSystemStats => https://taigaio.github.io/taiga-doc/dist/api.html#system-stats
func (s *StatsService) GetSystemStats() (*SystemStats, error) {
url := s.client.Request.MakeURL(fmt.Sprintf("%s/system", statsURI))
url := s.client.Request.MakeURL(statsURI, "system")
var respSystemStats SystemStats
err := s.client.Request.GetRequest(url, &respSystemStats)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *TaskService) GetAttachment(attachment *Attachment) (*Attachment, error)
}

// ListAttachments returns a list of Task attachments => https://taigaio.github.io/taiga-doc/dist/api.html#tasks-list-attachments
func (s *TaskService) ListAttachments(task interface{}) (*[]Attachment, error) {
func (s *TaskService) ListAttachments(task interface{}) ([]Attachment, error) {
t := Task{}
err := convertStructViaJSON(task, &t)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions user_stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *UserStoryService) List(queryParameters *UserStoryQueryParams) ([]UserSt
// Create creates a new User Story | https://taigaio.github.io/taiga-doc/dist/api.html#user-stories-create
//
// Available Meta: *UserStoryDetail
func (s *UserStoryService) Create(userStory UserStory) (*UserStory, error) {
func (s *UserStoryService) Create(userStory *UserStory) (*UserStory, error) {
url := s.client.APIURL + endpointUserStories
var newUserStory UserStoryDetail

Expand Down Expand Up @@ -102,7 +102,7 @@ func (s *UserStoryService) GetByRef(userStoryRef int, project *Project) (*UserSt

// Edit sends a PATCH request to edit a User Story -> https://taigaio.github.io/taiga-doc/dist/api.html#user-stories-edit
// Available Meta: UserStoryDetail
func (s *UserStoryService) Edit(userStory UserStory) (*UserStory, error) {
func (s *UserStoryService) Edit(userStory *UserStory) (*UserStory, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointUserStories, userStory.ID)
var responseUS UserStoryDetail

Expand Down Expand Up @@ -153,7 +153,7 @@ func (us *UserStory) RelateToEpic(TaigaClient *Client, EpicID int) (*EpicRelated
// Clone clones an existing UserStory with most fields
//
// Available Meta: UserStoryDetail
func (s *UserStoryService) Clone(srcUserStory UserStory) (*UserStory, error) {
func (s *UserStoryService) Clone(srcUserStory *UserStory) (*UserStory, error) {
srcUserStory.ID = 0
srcUserStory.Ref = 0
srcUserStory.Version = 0
Expand All @@ -179,7 +179,7 @@ func (us *UserStory) CloneUserStory(TaigaClient *Client) (*UserStory, error) {
us.ID = 0
us.Ref = 0
us.Version = 0
return TaigaClient.UserStory.Create(*us)
return TaigaClient.UserStory.Create(us)
}

// GetRelatedTasks returns all Tasks related to this UserStory
Expand Down

0 comments on commit 95d1aca

Please sign in to comment.