✨ 完善基础架构,新增部分问题接口
This commit is contained in:
33
api/problem.go
Normal file
33
api/problem.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"online_code/core"
|
||||
"online_code/models/param"
|
||||
"online_code/repository"
|
||||
"online_code/utils"
|
||||
)
|
||||
|
||||
type problemApi struct{}
|
||||
|
||||
func ProblemApi() *problemApi {
|
||||
return &problemApi{}
|
||||
}
|
||||
|
||||
func (problemApi) GetProbleList(ctx *gin.Context) {
|
||||
var p param.GetProblemList
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
core.R(ctx).FailWithMessage("参数错误: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
records, count, err := repository.ProblemService().GetList(p)
|
||||
if err != nil {
|
||||
core.R(ctx).FailWithMessage("获取题目列表失败: " + err.Error())
|
||||
return
|
||||
}
|
||||
// 计算总页码
|
||||
totalPage := utils.GenTotalPage(count, p.Size)
|
||||
// 返回结果
|
||||
core.R(ctx).OkWithData(core.PageData{Current: p.Current, Size: p.Size, Total: count, TotalPage: totalPage, Records: records})
|
||||
}
|
Reference in New Issue
Block a user