From f383eab282a2c6ba45077d3983fb39c5a025fffb Mon Sep 17 00:00:00 2001 From: jiayuqi7813 <63686458+jiayuqi7813@users.noreply.github.com> Date: Tue, 12 Jul 2022 03:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/admin/challenge.go | 37 +++++++++++++++++++++++++++++++++++++ routers/router.go | 2 ++ snctf.db | Bin 65536 -> 65536 bytes type/adminTypes.go | 12 ++++++++++++ 4 files changed, 51 insertions(+) diff --git a/api/admin/challenge.go b/api/admin/challenge.go index 2bcc1a0..7108198 100644 --- a/api/admin/challenge.go +++ b/api/admin/challenge.go @@ -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 diff --git a/routers/router.go b/routers/router.go index d2d6112..6ecbc66 100644 --- a/routers/router.go +++ b/routers/router.go @@ -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) //创建新公告 diff --git a/snctf.db b/snctf.db index 5de7dc4ab80eb157f35421767e550c3deeae15c9..24fc357ea8a975134feb3ae784f2f0916c7364e2 100644 GIT binary patch delta 352 zcmZo@U}7N&WFYEY_J3EMEV*`<_tRQg?j>#X+t8wsefxyj*3MKqr{AU=rK#n)$;b0bJ1hLqm z3==k>9Gf{O53@Yyv#s4P)=xDwGUj5IWGuzp$t%XL)Lp@#KL0>Wuu8_w74iD$gsds>)fCnVZV|A}uE| zy}BeLvp61zK%ClVTf1MZpBlr&&0x=Dh)_Ct^Zq2p8=Dma4)IS;=w}gOXJ=(*WMpFl zk*ur?3=C{6ER#Q+R|C4Bjo*QTS(FiIt0_B_VZz3LhJmdllZRQJ6Jmj(kuevuBqPWb fhK5Z1?-&H&;y|g%ckWAa8-t7mIo^n6(E|klS1C=q diff --git a/type/adminTypes.go b/type/adminTypes.go index 1b807c0..590c983 100644 --- a/type/adminTypes.go +++ b/type/adminTypes.go @@ -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 {