新增查询全部用户api

This commit is contained in:
jiayuqi7813
2022-06-27 20:00:50 +08:00
parent f213f1d0c3
commit 4b7ef7b4a7
4 changed files with 49 additions and 20 deletions

View File

@@ -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) {

View File

@@ -6,7 +6,6 @@ import (
"main.go/api/admin"
)
func Initrouter() {
router := gin.Default()
api_v1 := router.Group("/api/v1")
@@ -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")
}

BIN
snctf.db

Binary file not shown.

View File

@@ -96,6 +96,17 @@ 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"`