Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
flag: filter (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 authored Dec 12, 2020
1 parent 21854fb commit 9176393
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 0.7.2+dev(`master`)

### Added

* 管理员后台可筛选 Flag。
* Timer 增加返回当前服务器时间戳。
* gofmt CI 检查代码。
* README 加入 Sourcegraph 链接。
Expand All @@ -12,9 +14,11 @@
* 数据库版本检测。

### Changed

* 日志包更换为 `unknwon.dev/clog/v2`
* 折叠显示 README 图片。
* 修改 GitHub 打赏链接。

### Removed

* 去除消息队列功能。
36 changes: 34 additions & 2 deletions internal/game/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ func GetFlags(c *gin.Context) (int, interface{}) {
pageStr := c.DefaultQuery("page", "1")
perStr := c.DefaultQuery("per", "15")

// filter
roundStr := c.DefaultQuery("round", "0")
teamStr := c.DefaultQuery("team", "0")
challengeStr := c.DefaultQuery("challenge", "0")

round, err := strconv.Atoi(roundStr)
if err != nil || round < 0 {
return utils.MakeErrJSON(400, 40022,
locales.I18n.T(c.GetString("lang"), "general.error_query"),
)
}
teamID, err := strconv.Atoi(teamStr)
if err != nil || teamID < 0 {
return utils.MakeErrJSON(400, 40022,
locales.I18n.T(c.GetString("lang"), "general.error_query"),
)
}
challengeID, err := strconv.Atoi(challengeStr)
if err != nil || challengeID < 0 {
return utils.MakeErrJSON(400, 40022,
locales.I18n.T(c.GetString("lang"), "general.error_query"),
)
}

page, err := strconv.Atoi(pageStr)
if err != nil || page <= 0 {
return utils.MakeErrJSON(400, 40022,
Expand All @@ -155,10 +179,18 @@ func GetFlags(c *gin.Context) (int, interface{}) {
}

var total int
db.MySQL.Model(&db.Flag{}).Count(&total)
db.MySQL.Model(&db.Flag{}).Where(&db.Flag{
TeamID: uint(teamID),
ChallengeID: uint(challengeID),
Round: round,
}).Count(&total)

var flags []db.Flag
db.MySQL.Model(&db.Flag{}).Offset((page - 1) * per).Limit(per).Find(&flags)
db.MySQL.Model(&db.Flag{}).Where(&db.Flag{
TeamID: uint(teamID),
ChallengeID: uint(challengeID),
Round: round,
}).Offset((page - 1) * per).Limit(per).Find(&flags)

return utils.MakeSuccessJSON(gin.H{
"array": flags,
Expand Down

0 comments on commit 9176393

Please sign in to comment.