mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
feat: add missing query params to wakatime endpoints (resolve #109)
This commit is contained in:
@ -22,7 +22,7 @@ type BadgeData struct {
|
||||
|
||||
func NewBadgeDataFrom(summary *models.Summary, filters *models.Filters) *BadgeData {
|
||||
var total time.Duration
|
||||
if hasFilter, _, _ := filters.First(); hasFilter {
|
||||
if hasFilter, _, _ := filters.One(); hasFilter {
|
||||
total = summary.TotalTimeByFilters(filters)
|
||||
} else {
|
||||
total = summary.TotalTime()
|
||||
|
@ -29,7 +29,7 @@ func NewFiltersWith(entity uint8, key string) *Filters {
|
||||
return &Filters{}
|
||||
}
|
||||
|
||||
func (f *Filters) First() (bool, uint8, string) {
|
||||
func (f *Filters) One() (bool, uint8, string) {
|
||||
if f.Project != "" {
|
||||
return true, SummaryProject, f.Project
|
||||
} else if f.OS != "" {
|
||||
@ -43,25 +43,3 @@ func (f *Filters) First() (bool, uint8, string) {
|
||||
}
|
||||
return false, 0, ""
|
||||
}
|
||||
|
||||
func (f *Filters) All() []*FilterElement {
|
||||
all := make([]*FilterElement, 0)
|
||||
|
||||
if f.Project != "" {
|
||||
all = append(all, &FilterElement{Type: SummaryProject, Key: f.Project})
|
||||
}
|
||||
if f.Editor != "" {
|
||||
all = append(all, &FilterElement{Type: SummaryEditor, Key: f.Editor})
|
||||
}
|
||||
if f.Language != "" {
|
||||
all = append(all, &FilterElement{Type: SummaryLanguage, Key: f.Language})
|
||||
}
|
||||
if f.Machine != "" {
|
||||
all = append(all, &FilterElement{Type: SummaryMachine, Key: f.Machine})
|
||||
}
|
||||
if f.OS != "" {
|
||||
all = append(all, &FilterElement{Type: SummaryOS, Key: f.OS})
|
||||
}
|
||||
|
||||
return all
|
||||
}
|
||||
|
@ -24,6 +24,18 @@ const (
|
||||
IntervalPast30Days string = "30_days"
|
||||
IntervalPast12Months string = "12_months"
|
||||
IntervalAny string = "any"
|
||||
|
||||
// https://wakatime.com/developers/#summaries
|
||||
IntervalWakatimeToday string = "Today"
|
||||
IntervalWakatimeYesterday string = "Yesterday"
|
||||
IntervalWakatimeLast7Days string = "Last 7 Days"
|
||||
IntervalWakatimeLast7DaysYesterday string = "Last 7 Days from Yesterday"
|
||||
IntervalWakatimeLast14Days string = "Last 14 Days"
|
||||
IntervalWakatimeLast30Days string = "Last 30 Days"
|
||||
IntervalWakatimeThisWeek string = "This Week"
|
||||
IntervalWakatimeLastWeek string = "Last Week"
|
||||
IntervalWakatimeThisMonth string = "This Month"
|
||||
IntervalWakatimeLastMonth string = "Last Month"
|
||||
)
|
||||
|
||||
func Intervals() []string {
|
||||
@ -188,11 +200,12 @@ func (s *Summary) TotalTimeByKey(entityType uint8, key string) (timeSum time.Dur
|
||||
return timeSum
|
||||
}
|
||||
|
||||
func (s *Summary) TotalTimeByFilters(filter *Filters) (timeSum time.Duration) {
|
||||
for _, f := range filter.All() {
|
||||
timeSum += s.TotalTimeByKey(f.Type, f.Key)
|
||||
func (s *Summary) TotalTimeByFilters(filters *Filters) (timeSum time.Duration) {
|
||||
do, typeId, key := filters.One()
|
||||
if do {
|
||||
return s.TotalTimeByKey(typeId, key)
|
||||
}
|
||||
return timeSum
|
||||
return s.TotalTime()
|
||||
}
|
||||
|
||||
func (s *Summary) WithResolvedAliases(resolve AliasResolver) *Summary {
|
||||
|
Reference in New Issue
Block a user