-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from SJTU-jCourse/feat/statistic
Feat/statistic
- Loading branch information
Showing
30 changed files
with
2,079 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handler | ||
|
||
import ( | ||
"jcourse_go/model/dto" | ||
"jcourse_go/model/model" | ||
"jcourse_go/service" | ||
"jcourse_go/util" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func GetStatisticHandler(c *gin.Context) { | ||
request := dto.StatisticRequest{ | ||
StartTime: 0, | ||
EndTime: 0, | ||
PeriodKeys: []model.PeriodInfoKey{}, | ||
} | ||
if err := c.ShouldBindJSON(&request); err != nil { | ||
c.JSON(http.StatusBadRequest, dto.BaseResponse{Message: "参数错误"}) | ||
return | ||
} | ||
if request.StartTime > request.EndTime { | ||
c.JSON(http.StatusBadRequest, dto.BaseResponse{Message: "参数错误"}) | ||
return | ||
} | ||
filter := model.StatisticFilter{ | ||
StartDate: util.FormatDate(time.Unix(request.StartTime, 0)), | ||
EndDate: util.FormatDate(time.Unix(request.EndTime, 0)), | ||
PeriodInfoKeys: request.PeriodKeys, | ||
} | ||
dailyInfos, periodInfos, err := service.GetStatistics(c, filter) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, dto.BaseResponse{Message: "内部错误"}) | ||
return | ||
} | ||
c.JSON(http.StatusOK, dto.StatisticResponse{ | ||
DailyInfos: dailyInfos, | ||
PeriodInfos: periodInfos, | ||
}) | ||
} |
Oops, something went wrong.