修复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