online_code/repository/problem.go

32 lines
803 B
Go

package repository
import (
"online_code/client"
"online_code/models/entity"
"online_code/models/param"
)
type problemService struct{}
func ProblemService() *problemService {
return &problemService{}
}
// GetList 获取题目列表
func (problemService) GetList(p param.GetProblemList) (records entity.Problem, count int64, err error) {
sel := client.MySQL.Scopes(page(p.Current, p.Size))
if p.Keyword != "" {
sel.Where("title LIKE ? OR content like ?", "%"+p.Keyword+"%", "%"+p.Keyword+"%")
}
err = sel.Order("updated_at DESC").Find(&records).Offset(-1).Limit(-1).Count(&count).Error
return
}
// GetProblemInfo 获取题目详情
func (problemService) GetProblemInfo(id int) (problem entity.Problem, err error) {
err = client.MySQL.Where("id = ?", id).Find(&problem).Error
return
}