Compare commits
3 Commits
991165125f
...
569e6618a8
Author | SHA1 | Date | |
---|---|---|---|
569e6618a8 | |||
fb5f8ca2a5 | |||
090acb0454 |
31
api/submit.go
Normal file
31
api/submit.go
Normal file
@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"online_code/core"
|
||||
"online_code/models/param"
|
||||
"online_code/repository"
|
||||
)
|
||||
|
||||
type submitApi struct{}
|
||||
|
||||
func SubmitApi() *submitApi {
|
||||
return &submitApi{}
|
||||
}
|
||||
|
||||
func (submitApi) GetSubmitList(c *gin.Context) {
|
||||
var p param.GetSubmitList
|
||||
if err := c.ShouldBind(&p); err != nil {
|
||||
core.R(c).FailWithMessage("参数错误: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
records, count, err := repository.SubmitService().GetList(p)
|
||||
if err != nil {
|
||||
core.R(c).FailWithMessage("获取提交列表失败: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
core.R(c).OkDataPage(count, core.PageData{Current: p.Current, Size: p.Size, Total: count, Records: records})
|
||||
}
|
32
api/user.go
Normal file
32
api/user.go
Normal file
@ -0,0 +1,32 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"online_code/client"
|
||||
"online_code/core"
|
||||
"online_code/models/entity"
|
||||
)
|
||||
|
||||
type userApi struct{}
|
||||
|
||||
func UserApi() *userApi {
|
||||
return &userApi{}
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户详情
|
||||
func (userApi) GetUserInfo(ctx *gin.Context) {
|
||||
// 获取用户信息
|
||||
identity := ctx.Param("identity")
|
||||
if identity == "" {
|
||||
core.R(ctx).FailWithMessage("参数不能为空: identity")
|
||||
return
|
||||
}
|
||||
|
||||
userData := entity.UserBasic{}
|
||||
err := client.MySQL.Omit("password").Where("identity = ?", identity).Take(&userData).Error
|
||||
if err != nil {
|
||||
core.R(ctx).FailWithMessage("获取用户信息失败: " + err.Error())
|
||||
return
|
||||
}
|
||||
core.R(ctx).OkWithData(userData)
|
||||
}
|
@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"online_code/utils"
|
||||
)
|
||||
|
||||
// 返回数据包装
|
||||
@ -59,6 +60,15 @@ func (r rs) OkDetailed(data interface{}, message string) {
|
||||
r.Result(SUCCESS, data, message)
|
||||
}
|
||||
|
||||
// OkDataPage 返回分页数据
|
||||
func (r rs) OkDataPage(count int64, page PageData) {
|
||||
// 计算总页码
|
||||
totalPage := utils.GenTotalPage(count, page.Size)
|
||||
page.TotalPage = totalPage
|
||||
// 返回结果
|
||||
r.Result(SUCCESS, page, "操作成功")
|
||||
}
|
||||
|
||||
// Fail 返回默认失败
|
||||
func (r rs) Fail() {
|
||||
r.Result(ERROR, nil, "操作失败")
|
||||
|
1
go.mod
1
go.mod
@ -9,7 +9,6 @@ require (
|
||||
github.com/fsnotify/fsnotify v1.5.1
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/spf13/viper v1.10.1
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
|
8
models/param/submit.go
Normal file
8
models/param/submit.go
Normal file
@ -0,0 +1,8 @@
|
||||
package param
|
||||
|
||||
type GetSubmitList struct {
|
||||
page
|
||||
ProblemIdentity string `json:"problemIdentity" form:"problemIdentity"`
|
||||
UserIdentity string `json:"userIdentity" form:"userIdentity"`
|
||||
Status int `json:"status" form:"status"`
|
||||
}
|
28
repository/submit.go
Normal file
28
repository/submit.go
Normal file
@ -0,0 +1,28 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"online_code/client"
|
||||
"online_code/models/entity"
|
||||
"online_code/models/param"
|
||||
)
|
||||
|
||||
type submitService struct{}
|
||||
|
||||
func SubmitService() *submitService {
|
||||
return &submitService{}
|
||||
}
|
||||
|
||||
func (submitService) GetList(p param.GetSubmitList) (records []entity.SubmitBasic, count int64, err error) {
|
||||
tx := client.MySQL.Scopes(page(p.Current, p.Size))
|
||||
if p.ProblemIdentity != "" {
|
||||
tx = tx.Where("problem_identity = ?", p.ProblemIdentity)
|
||||
}
|
||||
if p.UserIdentity != "" {
|
||||
tx = tx.Where("user_identity = ?", p.UserIdentity)
|
||||
}
|
||||
if p.Status != 0 && p.Status != 1 && p.Status != 2 {
|
||||
tx = tx.Where("status = ?", p.Status)
|
||||
}
|
||||
err = tx.Offset(-1).Limit(-1).Count(&count).Find(&records).Error
|
||||
return
|
||||
}
|
7
repository/user.go
Normal file
7
repository/user.go
Normal file
@ -0,0 +1,7 @@
|
||||
package repository
|
||||
|
||||
type userService struct{}
|
||||
|
||||
func UserService() *userService {
|
||||
return &userService{}
|
||||
}
|
@ -4,4 +4,5 @@ import "github.com/gin-gonic/gin"
|
||||
|
||||
func InitRoute(g *gin.RouterGroup) {
|
||||
problem(g.Group("/problem"))
|
||||
user(g.Group("/user"))
|
||||
}
|
||||
|
10
route/user.go
Normal file
10
route/user.go
Normal file
@ -0,0 +1,10 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"online_code/api"
|
||||
)
|
||||
|
||||
func user(g *gin.RouterGroup) {
|
||||
g.GET("/:identity", api.UserApi().GetUserInfo) // 获取用户详情
|
||||
}
|
Loading…
Reference in New Issue
Block a user