新增查询全部用户api
This commit is contained in:
19
api/user.go
19
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
|
// checkUsername 验证用户名是否符合中文数字字母下划线横杠,长度1到10位,返回true或false
|
||||||
func checkUsername(username string) bool {
|
func checkUsername(username string) bool {
|
||||||
if !(utf8.RuneCountInString(username) > 0) || !(utf8.RuneCountInString(username) < 11) {
|
if !(utf8.RuneCountInString(username) > 0) || !(utf8.RuneCountInString(username) < 11) {
|
||||||
|
@@ -6,8 +6,7 @@ import (
|
|||||||
"main.go/api/admin"
|
"main.go/api/admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Initrouter() {
|
||||||
func Initrouter(){
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
api_v1 := router.Group("/api/v1")
|
api_v1 := router.Group("/api/v1")
|
||||||
|
|
||||||
@@ -15,19 +14,19 @@ func Initrouter(){
|
|||||||
public := api_v1.Group("")
|
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用户可公开信息
|
//获取指定id用户可公开信息
|
||||||
public.GET("/user/:id",api.GetInfoByUserId)
|
public.GET("/user/:id", api.GetInfoByUserId)
|
||||||
//获取指定id用户分数
|
//获取指定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才能访问
|
// 普通用户api,需要用户登陆且Role=0才能访问
|
||||||
@@ -55,6 +54,9 @@ func Initrouter(){
|
|||||||
personal.GET("/solves/self", api.GetSelfSolves)
|
personal.GET("/solves/self", api.GetSelfSolves)
|
||||||
// 获取当前用户分数、排名
|
// 获取当前用户分数、排名
|
||||||
personal.GET("/score/self", api.GetSelfScoreAndRank)
|
personal.GET("/score/self", api.GetSelfScoreAndRank)
|
||||||
|
// 获取所有用户信息
|
||||||
|
personal.GET("/users", api.GetAllUserInfo)
|
||||||
|
|
||||||
// 校内排行api,暂时留空
|
// 校内排行api,暂时留空
|
||||||
}
|
}
|
||||||
// 管理员api,需要用户登陆且Role=1才能访问
|
// 管理员api,需要用户登陆且Role=1才能访问
|
||||||
@@ -65,8 +67,5 @@ func Initrouter(){
|
|||||||
manager.POST("/challenge", admin.NewChallenge)
|
manager.POST("/challenge", admin.NewChallenge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.Run(":9000")
|
router.Run(":9000")
|
||||||
}
|
}
|
||||||
|
@@ -96,18 +96,29 @@ type PublicInfoResponse struct {
|
|||||||
TeamID int `json:"team_id"`
|
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 定义获取题目的一个响应。
|
// ChallengeResponse 定义获取题目的一个响应。
|
||||||
type ChallengeResponse struct {
|
type ChallengeResponse struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Score int `json:"score"`
|
Score int `json:"score"`
|
||||||
Description string `json:"description"` //题目描述
|
Description string `json:"description"` //题目描述
|
||||||
Attachment []string `json:"attachment"` //题目附件
|
Attachment []string `json:"attachment"` //题目附件
|
||||||
Category string `json:"category"` //分类
|
Category string `json:"category"` //分类
|
||||||
Tags string `json:"tags"` //标签
|
Tags string `json:"tags"` //标签
|
||||||
Hints []string `json:"hints"` //提示
|
Hints []string `json:"hints"` //提示
|
||||||
SolverCount int `json:"solver_count"` //解决人数
|
SolverCount int `json:"solver_count"` //解决人数
|
||||||
IsSolved bool `json:"is_solved"` // true:已解决,false:未解决
|
IsSolved bool `json:"is_solved"` // true:已解决,false:未解决
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScoreRankResponse 定义获取当前用户分数和排名的一个响应。
|
// ScoreRankResponse 定义获取当前用户分数和排名的一个响应。
|
||||||
|
Reference in New Issue
Block a user