Skip to content

Commit

Permalink
MilestoneTotalInfo added for MilestoneService.List
Browse files Browse the repository at this point in the history
  • Loading branch information
theriverman committed May 23, 2020
1 parent 10c52d8 commit bf8b642
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 6 additions & 3 deletions milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type MilestoneService struct {
}

// List => https://taigaio.github.io/taiga-doc/dist/api.html#Milestones-list
func (s *MilestoneService) List(queryParams *MilestonesQueryParams) ([]Milestone, error) {
func (s *MilestoneService) List(queryParams *MilestonesQueryParams) ([]Milestone, *MilestoneTotalInfo, error) {
// prepare url & parameters
url := s.client.MakeURL(s.Endpoint)
if queryParams != nil {
Expand All @@ -30,9 +30,12 @@ func (s *MilestoneService) List(queryParams *MilestonesQueryParams) ([]Milestone
var Milestones []Milestone
httpResponse, err := s.client.Request.Get(url, &Milestones)
if err != nil {
return nil, err
return nil, nil, err
}
return Milestones, nil
mti := &MilestoneTotalInfo{}
mti.LoadFromHeaders(httpResponse)

return Milestones, mti, nil
}

// Create => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-create
Expand Down
24 changes: 23 additions & 1 deletion milestones.models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package taigo

import "time"
import (
"net/http"
"strconv"
"time"
)

// TODO
/*
Expand Down Expand Up @@ -38,3 +42,21 @@ type MilestonesQueryParams struct {
Project int `url:"project,omitempty"`
Closed bool `url:"closed,omitempty"`
}

// MilestoneTotalInfo holds the two extra headers returned by Taiga when filtering for milestones
//
// Taiga-Info-Total-Opened-Milestones: the number of opened milestones for this project
// Taiga-Info-Total-Closed-Milestones: the number of closed milestones for this project
//
// https://taigaio.github.io/taiga-doc/dist/api.html#milestones-list
type MilestoneTotalInfo struct {
TaigaInfoTotalOpenedMilestones int // Taiga-Info-Total-Opened-Milestones
TaigaInfoTotalClosedMilestones int // Taiga-Info-Total-Closed-Milestones
}

// LoadFromHeaders accepts an *http.Response struct and reads the relevant
// pagination headers returned by Taiga
func (m *MilestoneTotalInfo) LoadFromHeaders(response *http.Response) {
m.TaigaInfoTotalOpenedMilestones, _ = strconv.Atoi(response.Header.Get("Taiga-Info-Total-Opened-Milestones"))
m.TaigaInfoTotalClosedMilestones, _ = strconv.Atoi(response.Header.Get("Taiga-Info-Total-Closed-Milestones"))
}

0 comments on commit bf8b642

Please sign in to comment.