You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB
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.ProblemBasic, count int64, err error) {
sel := client.MySQL.Scopes(page(p.Current, p.Size)).Preload("ProblemCategories").Preload("ProblemCategories.CategoryBasic")
if p.Keyword != "" {
sel.Where("title LIKE ? OR content like ?", "%"+p.Keyword+"%", "%"+p.Keyword+"%")
}
if p.CategoryIdentity != "" {
sel.Joins("RIGHT JOINN problem_category pc on pc.problem_id = problem.id").
Where("pc.category_id= (SELECT cb.id FROM category cb WHERE cb.identity = ?)", p.CategoryIdentity)
}
err = sel.Order("updated_at DESC").Find(&records).Offset(-1).Limit(-1).Count(&count).Error
return
}
// GetProblemInfo 获取题目详情
func (problemService) GetProblemInfo(id int) (problem entity.ProblemBasic, err error) {
err = client.MySQL.Where("id = ?", id).Find(&problem).Error
return
}