From 4b7ef7b4a7f3761e7eeab3337c8dbc4409bbbb4b Mon Sep 17 00:00:00 2001 From: jiayuqi7813 <63686458+jiayuqi7813@users.noreply.github.com> Date: Mon, 27 Jun 2022 20:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E7=94=A8=E6=88=B7api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user.go | 19 +++++++++++++++++++ routers/router.go | 25 ++++++++++++------------- snctf.db | Bin 65536 -> 65536 bytes type/userTypes.go | 25 ++++++++++++++++++------- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/api/user.go b/api/user.go index 730e019..ac73996 100644 --- a/api/user.go +++ b/api/user.go @@ -203,6 +203,25 @@ func GetInfoByUserId(c *gin.Context) { } +// GetAllUserInfo 获取所有用户信息 +func GetAllUserInfo(c *gin.Context) { + var info PublicAllInfoResponse + var alla []PublicAllInfoResponse + Link() + DB := db.DBsnctf + rows, err := DB.Debug().Select([]string{"id", "username", "affiliation", "country", "website", "hidden"}).Table("user").Rows() + + if err != nil { + c.JSON(400, gin.H{"code": 400, "msg": "Get info error!"}) + return + } + for rows.Next() { + rows.Scan(&info.Id, &info.Username, &info.Affiliation, &info.Country, &info.Website, &info.Hidden) + alla = append(alla, info) + } + c.JSON(200, gin.H{"code": 200, "data": alla}) +} + // checkUsername 验证用户名是否符合中文数字字母下划线横杠,长度1到10位,返回true或false func checkUsername(username string) bool { if !(utf8.RuneCountInString(username) > 0) || !(utf8.RuneCountInString(username) < 11) { diff --git a/routers/router.go b/routers/router.go index 488bcff..b83b620 100644 --- a/routers/router.go +++ b/routers/router.go @@ -6,8 +6,7 @@ import ( "main.go/api/admin" ) - -func Initrouter(){ +func Initrouter() { router := gin.Default() api_v1 := router.Group("/api/v1") @@ -15,19 +14,19 @@ func Initrouter(){ public := api_v1.Group("") { //用户登录 - public.POST("/login",api.Login) + public.POST("/login", api.Login) //用户注册 - public.POST("/register",api.Register) + public.POST("/register", api.Register) //用户登出 - public.GET("/logout",api.Logout) + public.GET("/logout", api.Logout) //获取指定id用户可公开信息 - public.GET("/user/:id",api.GetInfoByUserId) + public.GET("/user/:id", api.GetInfoByUserId) //获取指定id用户分数 - public.GET("/score/:id",api.GetScoreByUserId) + public.GET("/score/:id", api.GetScoreByUserId) //获取所有用户分数,降序排列 - public.GET("/score",api.GetAllScore) + public.GET("/score", api.GetAllScore) //获取全部公告 - public.GET("/notice",api.GetAllNotices) + public.GET("/notice", api.GetAllNotices) } // 普通用户api,需要用户登陆且Role=0才能访问 @@ -55,6 +54,9 @@ func Initrouter(){ personal.GET("/solves/self", api.GetSelfSolves) // 获取当前用户分数、排名 personal.GET("/score/self", api.GetSelfScoreAndRank) + // 获取所有用户信息 + personal.GET("/users", api.GetAllUserInfo) + // 校内排行api,暂时留空 } // 管理员api,需要用户登陆且Role=1才能访问 @@ -65,8 +67,5 @@ func Initrouter(){ manager.POST("/challenge", admin.NewChallenge) } - - - router.Run(":9000") -} \ No newline at end of file +} diff --git a/snctf.db b/snctf.db index 9a96cdbf5ab02d90d30dca3f9f91dcaa3747111c..1f3a9aee7fb0d2da3894ae6fcbf121d9bbf35fff 100644 GIT binary patch delta 2023 zcma)7VQ5=b6n-!7y(I7D-FK3vXRtR>DLG6mf#3feM~f+(fyeyGS`Zth1JXc<_$^~W4yr#}Ys+$3#HZJ_r( zJ`VRg=iGD8J?Gwhp3mp`Nk4mNYR?nwp$q-z!D%Ja415ed%91j!$Yi?M=A0ri!>TZS z-oCwr5WC&Z+YcX3Mzy3KIS`K+Mlz+Pw7A}t*smv}kpqcjB9=3l3}|FBLg%rmeKYp@L0;Rl#6x>~;guW02Nuf1$52|VMmXp!!y85WWca73?qrz%+RZb z!f|bE_7#0Noz12*BYtE=p7XM0l9ySog-s@M#z1ELs6deP%QFnzgiCM^PJj*vA)wq> zZYUR(&y;sDE6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6g>FAy(4#sxX|1%XnBdVtU*JX}g92+Pc)MT!0TkVhX8-^I diff --git a/type/userTypes.go b/type/userTypes.go index 1983a08..c4b2cc3 100644 --- a/type/userTypes.go +++ b/type/userTypes.go @@ -96,18 +96,29 @@ type PublicInfoResponse struct { TeamID int `json:"team_id"` } +// PublicAllInfoResponse 定义返回所有用户公开信息结构体 暂时不显示队伍名称 +type PublicAllInfoResponse struct { + Id string `json:"id"` + Username string `json:"username"` + Affiliation string `json:"affiliation"` + Country string `json:"country"` + Website string `json:"website"` + TeamID string `json:"team_id"` + Hidden string `json:"hidden"` +} + // ChallengeResponse 定义获取题目的一个响应。 type ChallengeResponse struct { ID int `json:"id"` Name string `json:"name"` Score int `json:"score"` - Description string `json:"description"` //题目描述 - Attachment []string `json:"attachment"` //题目附件 - Category string `json:"category"` //分类 - Tags string `json:"tags"` //标签 - Hints []string `json:"hints"` //提示 - SolverCount int `json:"solver_count"` //解决人数 - IsSolved bool `json:"is_solved"` // true:已解决,false:未解决 + Description string `json:"description"` //题目描述 + Attachment []string `json:"attachment"` //题目附件 + Category string `json:"category"` //分类 + Tags string `json:"tags"` //标签 + Hints []string `json:"hints"` //提示 + SolverCount int `json:"solver_count"` //解决人数 + IsSolved bool `json:"is_solved"` // true:已解决,false:未解决 } // ScoreRankResponse 定义获取当前用户分数和排名的一个响应。