修复bug

This commit is contained in:
jiayuqi7813
2022-07-12 03:20:45 +08:00
parent c2a6a26615
commit f383eab282
4 changed files with 51 additions and 0 deletions

View File

@@ -23,6 +23,43 @@ type CrDb struct {
Visible int `json:"visible"`
}
//GetAllChallenges 获取所有题目
func GetAllChallenges(c *gin.Context) {
var challenges []Challenge
if err := getchallenge(&challenges); err != nil {
fmt.Println(err)
c.JSON(400, gin.H{"code": 400, "msg": "Get all challenges failure!"})
return
}
c.JSON(200, gin.H{"code": 200, "data": challenges})
}
//getchallenge 获取题目
func getchallenge(challenge *[]Challenge) error {
var attachmentString, hints string
api.Link()
DB := db.DBsnctf
command := "SELECT * FROM challenge;"
rows, err := DB.Raw(command).Rows()
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
var b Challenge
err := rows.Scan(&b.ID, &b.Name, &b.Score, &b.Flag, &b.Description, &attachmentString, &b.Category, &b.Tags, &hints, &b.Visible)
if err != nil {
return err
}
b.Attachment = strings.Split(attachmentString, ",")
b.Hints = strings.Split(hints, ",")
*challenge = append(*challenge, b)
}
return nil
}
//NewChallenge 新建一个题目
func NewChallenge(c *gin.Context) {
var request ChallengeRequest

View File

@@ -66,6 +66,8 @@ func Initrouter() {
manager.POST("/challenge", admin.NewChallenge)
// 删除题目 测试通过,但是分数不会同步删除
manager.DELETE("/challenge/:id", admin.DelChallenge)
// 获取所有题目,包括不可见题目
manager.GET("/challenges", admin.GetAllChallenges)
// 更新题目信息
manager.PUT("/challenge/:id", admin.EditChallenge)
//创建新公告

BIN
snctf.db

Binary file not shown.

View File

@@ -12,6 +12,18 @@ type ChallengeRequest struct {
Hints []string `json:"hints"`
Visible int `json:"visible"`
}
type ChallengeRequest2 struct {
Id int `json:"id"`
Name string `json:"name" binding:"required"`
Score int `json:"score" binding:"required"`
Flag string `json:"flag"` // 暂时一个题只能一个flag
Description string `json:"description"`
Attachment []string `json:"attachment"`
Category string `json:"category" binding:"required"`
Tags string `json:"tags"`
Hints []string `json:"hints"`
Visible int `json:"visible"`
}
// NoticeRequest 定义新增公告的一个请求
type NoticeRequest struct {