From 090acb045413d04987f77f280063c93990047d3c Mon Sep 17 00:00:00 2001 From: Eg <1711788888@qq.com> Date: Thu, 2 Jun 2022 16:21:42 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/submit.go | 31 +++++++++++++++++++++++++++++++ models/param/submit.go | 8 ++++++++ repository/submit.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 api/submit.go create mode 100644 models/param/submit.go create mode 100644 repository/submit.go diff --git a/api/submit.go b/api/submit.go new file mode 100644 index 0000000..af0a654 --- /dev/null +++ b/api/submit.go @@ -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}) +} diff --git a/models/param/submit.go b/models/param/submit.go new file mode 100644 index 0000000..97bfaff --- /dev/null +++ b/models/param/submit.go @@ -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"` +} diff --git a/repository/submit.go b/repository/submit.go new file mode 100644 index 0000000..ab2ba68 --- /dev/null +++ b/repository/submit.go @@ -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 +}