-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_summary.go
62 lines (50 loc) · 1.7 KB
/
api_summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package neocortex
import (
"net/http"
"github.com/araddon/dateparse"
"github.com/gin-gonic/gin"
)
func (api *API) registerSummaryAPI(r *gin.RouterGroup) {
r.GET("/summary", func(c *gin.Context) {
frame := TimeFrame{}
preset := TimeFramePreset(c.Query("preset"))
if preset != DayPreset && preset != WeekPreset && preset != MonthPreset && preset != YearPreset {
from, err := dateparse.ParseAny(c.Query("from"))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "from date not found"})
return
}
to, err := dateparse.ParseAny(c.Query("to"))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "to date not found"})
return
}
frame.From = from
frame.To = to
} else {
frame.Preset = preset
}
// fromScratch := time.Date(2019, 1, 1, 0, 0, 0, 0, time.Local)
// fromScratchFrame := TimeFrame{From: fromScratch, To: frame.From, PageSize: frame.PageSize, PageNum: frame.PageNum}
// pastSummary, err := api.repository.Summary(fromScratchFrame)
// if err != nil {
// c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
// return
// }
summary, err := api.repository.Summary(frame)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// summary.RecurrentUsers = pastSummary.RecurrentUsers - summary.RecurrentUsers
// for timezone, rec := range pastSummary.UsersByTimezone {
// summary.UsersByTimezone[timezone] = UsersSummary{
// News: rec.News - summary.UsersByTimezone[timezone].News,
// Recurrents: rec.Recurrents - summary.UsersByTimezone[timezone].Recurrents,
// }
// }
c.JSON(http.StatusOK, gin.H{
"data": summary,
})
})
}