mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: support project query param for alltime endpoint
This commit is contained in:
parent
84e9559860
commit
a8009e107d
@ -2,11 +2,11 @@ package v1
|
|||||||
|
|
||||||
// https://wakatime.com/developers#all_time_since_today
|
// https://wakatime.com/developers#all_time_since_today
|
||||||
|
|
||||||
type AllTimeVieModel struct {
|
type AllTimeViewModel struct {
|
||||||
Data *AllTimeVieModelData `json:"data"`
|
Data *AllTimeViewModelData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AllTimeVieModelData struct {
|
type AllTimeViewModelData struct {
|
||||||
Seconds float32 `json:"seconds"` // total number of seconds logged since account created
|
Seconds float32 `json:"seconds"` // total number of seconds logged since account created
|
||||||
Text string `json:"text"` // total time logged since account created as human readable string>
|
Text string `json:"text"` // total time logged since account created as human readable string>
|
||||||
IsUpToDate bool `json:"is_up_to_date"` // true if the stats are up to date; when false, a 202 response code is returned and stats will be refreshed soon>
|
IsUpToDate bool `json:"is_up_to_date"` // true if the stats are up to date; when false, a 202 response code is returned and stats will be refreshed soon>
|
||||||
|
@ -138,3 +138,21 @@ func (s *Summary) TotalTime() time.Duration {
|
|||||||
|
|
||||||
return timeSum
|
return timeSum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Summary) TotalTimeBy(entityType uint8, key string) time.Duration {
|
||||||
|
var timeSum time.Duration
|
||||||
|
|
||||||
|
mappedItems := s.MappedItems()
|
||||||
|
|
||||||
|
// calculate total duration from any of the present sets of items
|
||||||
|
if items := mappedItems[entityType]; len(*items) > 0 {
|
||||||
|
for _, item := range *items {
|
||||||
|
if item.Key != key {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
timeSum += item.Total
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return timeSum
|
||||||
|
}
|
||||||
|
@ -44,9 +44,15 @@ func (h *CompatV1AllHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
total := summary.TotalTime()
|
var total time.Duration
|
||||||
vm := &v1.AllTimeVieModel{
|
if key := values.Get("project"); key != "" {
|
||||||
Data: &v1.AllTimeVieModelData{
|
total = summary.TotalTimeBy(models.SummaryProject, key)
|
||||||
|
} else {
|
||||||
|
total = summary.TotalTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
vm := &v1.AllTimeViewModel{
|
||||||
|
Data: &v1.AllTimeViewModelData{
|
||||||
Seconds: float32(total),
|
Seconds: float32(total),
|
||||||
Text: utils.FmtWakatimeDuration(total * time.Second),
|
Text: utils.FmtWakatimeDuration(total * time.Second),
|
||||||
IsUpToDate: true,
|
IsUpToDate: true,
|
||||||
|
@ -1 +1 @@
|
|||||||
1.9.1
|
1.9.2
|
Loading…
Reference in New Issue
Block a user