@@ -15,7 +15,7 @@ import (
1515 "gorm.io/gorm"
1616)
1717
18- func getDashboardTime (t string , startTimestamp int64 , endTimestamp int64 , timezoneLocation * time.Location ) (time.Time , time.Time , model.TimeSpanType ) {
18+ func getDashboardTime (t string , timespan string , startTimestamp int64 , endTimestamp int64 , timezoneLocation * time.Location ) (time.Time , time.Time , model.TimeSpanType ) {
1919 end := time .Now ()
2020 if endTimestamp != 0 {
2121 end = time .Unix (endTimestamp , 0 )
@@ -47,6 +47,10 @@ func getDashboardTime(t string, startTimestamp int64, endTimestamp int64, timezo
4747 if startTimestamp != 0 {
4848 start = time .Unix (startTimestamp , 0 )
4949 }
50+ switch model .TimeSpanType (timespan ) {
51+ case model .TimeSpanDay , model .TimeSpanHour :
52+ timeSpan = model .TimeSpanType (timespan )
53+ }
5054 return start , end , timeSpan
5155}
5256
@@ -150,13 +154,15 @@ func fillGaps(data []*model.ChartData, start, end time.Time, t model.TimeSpanTyp
150154// @Param start_timestamp query int64 false "Start second timestamp"
151155// @Param end_timestamp query int64 false "End second timestamp"
152156// @Param timezone query string false "Timezone, default is Local"
157+ // @Param timespan query string false "Time span type (day, hour)"
153158// @Success 200 {object} middleware.APIResponse{data=model.DashboardResponse}
154159// @Router /api/dashboard/ [get]
155160func GetDashboard (c * gin.Context ) {
156161 startTimestamp , _ := strconv .ParseInt (c .Query ("start_timestamp" ), 10 , 64 )
157162 endTimestamp , _ := strconv .ParseInt (c .Query ("end_timestamp" ), 10 , 64 )
158163 timezoneLocation , _ := time .LoadLocation (c .DefaultQuery ("timezone" , "Local" ))
159- start , end , timeSpan := getDashboardTime (c .Query ("type" ), startTimestamp , endTimestamp , timezoneLocation )
164+ timespan := c .Query ("timespan" )
165+ start , end , timeSpan := getDashboardTime (c .Query ("type" ), timespan , startTimestamp , endTimestamp , timezoneLocation )
160166 modelName := c .Query ("model" )
161167 channelStr := c .Query ("channel" )
162168 channelID , _ := strconv .Atoi (channelStr )
@@ -194,6 +200,7 @@ func GetDashboard(c *gin.Context) {
194200// @Param start_timestamp query int64 false "Start second timestamp"
195201// @Param end_timestamp query int64 false "End second timestamp"
196202// @Param timezone query string false "Timezone, default is Local"
203+ // @Param timespan query string false "Time span type (day, hour)"
197204// @Success 200 {object} middleware.APIResponse{data=model.GroupDashboardResponse}
198205// @Router /api/dashboard/{group} [get]
199206func GetGroupDashboard (c * gin.Context ) {
@@ -206,7 +213,8 @@ func GetGroupDashboard(c *gin.Context) {
206213 startTimestamp , _ := strconv .ParseInt (c .Query ("start_timestamp" ), 10 , 64 )
207214 endTimestamp , _ := strconv .ParseInt (c .Query ("end_timestamp" ), 10 , 64 )
208215 timezoneLocation , _ := time .LoadLocation (c .DefaultQuery ("timezone" , "Local" ))
209- start , end , timeSpan := getDashboardTime (c .Query ("type" ), startTimestamp , endTimestamp , timezoneLocation )
216+ timespan := c .Query ("timespan" )
217+ start , end , timeSpan := getDashboardTime (c .Query ("type" ), timespan , startTimestamp , endTimestamp , timezoneLocation )
210218 tokenName := c .Query ("token_name" )
211219 modelName := c .Query ("model" )
212220
0 commit comments