Просмотр исходного кода

feat: timespan query file support (#200)

zijiren 7 месяцев назад
Родитель
Сommit
7e49fad07c
4 измененных файлов с 43 добавлено и 3 удалено
  1. 11 3
      core/controller/dashboard.go
  2. 12 0
      core/docs/docs.go
  3. 12 0
      core/docs/swagger.json
  4. 8 0
      core/docs/swagger.yaml

+ 11 - 3
core/controller/dashboard.go

@@ -15,7 +15,7 @@ import (
 	"gorm.io/gorm"
 	"gorm.io/gorm"
 )
 )
 
 
-func getDashboardTime(t string, startTimestamp int64, endTimestamp int64, timezoneLocation *time.Location) (time.Time, time.Time, model.TimeSpanType) {
+func getDashboardTime(t string, timespan string, startTimestamp int64, endTimestamp int64, timezoneLocation *time.Location) (time.Time, time.Time, model.TimeSpanType) {
 	end := time.Now()
 	end := time.Now()
 	if endTimestamp != 0 {
 	if endTimestamp != 0 {
 		end = time.Unix(endTimestamp, 0)
 		end = time.Unix(endTimestamp, 0)
@@ -47,6 +47,10 @@ func getDashboardTime(t string, startTimestamp int64, endTimestamp int64, timezo
 	if startTimestamp != 0 {
 	if startTimestamp != 0 {
 		start = time.Unix(startTimestamp, 0)
 		start = time.Unix(startTimestamp, 0)
 	}
 	}
+	switch model.TimeSpanType(timespan) {
+	case model.TimeSpanDay, model.TimeSpanHour:
+		timeSpan = model.TimeSpanType(timespan)
+	}
 	return start, end, timeSpan
 	return start, end, timeSpan
 }
 }
 
 
@@ -150,13 +154,15 @@ func fillGaps(data []*model.ChartData, start, end time.Time, t model.TimeSpanTyp
 //	@Param			start_timestamp	query		int64	false	"Start second timestamp"
 //	@Param			start_timestamp	query		int64	false	"Start second timestamp"
 //	@Param			end_timestamp	query		int64	false	"End second timestamp"
 //	@Param			end_timestamp	query		int64	false	"End second timestamp"
 //	@Param			timezone		query		string	false	"Timezone, default is Local"
 //	@Param			timezone		query		string	false	"Timezone, default is Local"
+//	@Param			timespan		query		string	false	"Time span type (day, hour)"
 //	@Success		200				{object}	middleware.APIResponse{data=model.DashboardResponse}
 //	@Success		200				{object}	middleware.APIResponse{data=model.DashboardResponse}
 //	@Router			/api/dashboard/ [get]
 //	@Router			/api/dashboard/ [get]
 func GetDashboard(c *gin.Context) {
 func GetDashboard(c *gin.Context) {
 	startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
 	startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
 	endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
 	endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
 	timezoneLocation, _ := time.LoadLocation(c.DefaultQuery("timezone", "Local"))
 	timezoneLocation, _ := time.LoadLocation(c.DefaultQuery("timezone", "Local"))
-	start, end, timeSpan := getDashboardTime(c.Query("type"), startTimestamp, endTimestamp, timezoneLocation)
+	timespan := c.Query("timespan")
+	start, end, timeSpan := getDashboardTime(c.Query("type"), timespan, startTimestamp, endTimestamp, timezoneLocation)
 	modelName := c.Query("model")
 	modelName := c.Query("model")
 	channelStr := c.Query("channel")
 	channelStr := c.Query("channel")
 	channelID, _ := strconv.Atoi(channelStr)
 	channelID, _ := strconv.Atoi(channelStr)
@@ -194,6 +200,7 @@ func GetDashboard(c *gin.Context) {
 //	@Param			start_timestamp	query		int64	false	"Start second timestamp"
 //	@Param			start_timestamp	query		int64	false	"Start second timestamp"
 //	@Param			end_timestamp	query		int64	false	"End second timestamp"
 //	@Param			end_timestamp	query		int64	false	"End second timestamp"
 //	@Param			timezone		query		string	false	"Timezone, default is Local"
 //	@Param			timezone		query		string	false	"Timezone, default is Local"
+//	@Param			timespan		query		string	false	"Time span type (day, hour)"
 //	@Success		200				{object}	middleware.APIResponse{data=model.GroupDashboardResponse}
 //	@Success		200				{object}	middleware.APIResponse{data=model.GroupDashboardResponse}
 //	@Router			/api/dashboard/{group} [get]
 //	@Router			/api/dashboard/{group} [get]
 func GetGroupDashboard(c *gin.Context) {
 func GetGroupDashboard(c *gin.Context) {
@@ -206,7 +213,8 @@ func GetGroupDashboard(c *gin.Context) {
 	startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
 	startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
 	endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
 	endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
 	timezoneLocation, _ := time.LoadLocation(c.DefaultQuery("timezone", "Local"))
 	timezoneLocation, _ := time.LoadLocation(c.DefaultQuery("timezone", "Local"))
-	start, end, timeSpan := getDashboardTime(c.Query("type"), startTimestamp, endTimestamp, timezoneLocation)
+	timespan := c.Query("timespan")
+	start, end, timeSpan := getDashboardTime(c.Query("type"), timespan, startTimestamp, endTimestamp, timezoneLocation)
 	tokenName := c.Query("token_name")
 	tokenName := c.Query("token_name")
 	modelName := c.Query("model")
 	modelName := c.Query("model")
 
 

+ 12 - 0
core/docs/docs.go

@@ -972,6 +972,12 @@ const docTemplate = `{
                         "description": "Timezone, default is Local",
                         "description": "Timezone, default is Local",
                         "name": "timezone",
                         "name": "timezone",
                         "in": "query"
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "Time span type (day, hour)",
+                        "name": "timespan",
+                        "in": "query"
                     }
                     }
                 ],
                 ],
                 "responses": {
                 "responses": {
@@ -1054,6 +1060,12 @@ const docTemplate = `{
                         "description": "Timezone, default is Local",
                         "description": "Timezone, default is Local",
                         "name": "timezone",
                         "name": "timezone",
                         "in": "query"
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "Time span type (day, hour)",
+                        "name": "timespan",
+                        "in": "query"
                     }
                     }
                 ],
                 ],
                 "responses": {
                 "responses": {

+ 12 - 0
core/docs/swagger.json

@@ -963,6 +963,12 @@
                         "description": "Timezone, default is Local",
                         "description": "Timezone, default is Local",
                         "name": "timezone",
                         "name": "timezone",
                         "in": "query"
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "Time span type (day, hour)",
+                        "name": "timespan",
+                        "in": "query"
                     }
                     }
                 ],
                 ],
                 "responses": {
                 "responses": {
@@ -1045,6 +1051,12 @@
                         "description": "Timezone, default is Local",
                         "description": "Timezone, default is Local",
                         "name": "timezone",
                         "name": "timezone",
                         "in": "query"
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "Time span type (day, hour)",
+                        "name": "timespan",
+                        "in": "query"
                     }
                     }
                 ],
                 ],
                 "responses": {
                 "responses": {

+ 8 - 0
core/docs/swagger.yaml

@@ -2296,6 +2296,10 @@ paths:
         in: query
         in: query
         name: timezone
         name: timezone
         type: string
         type: string
+      - description: Time span type (day, hour)
+        in: query
+        name: timespan
+        type: string
       produces:
       produces:
       - application/json
       - application/json
       responses:
       responses:
@@ -2346,6 +2350,10 @@ paths:
         in: query
         in: query
         name: timezone
         name: timezone
         type: string
         type: string
+      - description: Time span type (day, hour)
+        in: query
+        name: timespan
+        type: string
       produces:
       produces:
       - application/json
       - application/json
       responses:
       responses: