🎨 新增获取提交列表接口

This commit is contained in:
loser 2022-06-02 16:21:42 +08:00
parent 991165125f
commit 090acb0454
3 changed files with 67 additions and 0 deletions

31
api/submit.go Normal file
View 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})
}

8
models/param/submit.go Normal file
View 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
View 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
}