feat: 🎸 课程列表增加分类id参数
This commit is contained in:
parent
09c7f0f6a5
commit
0ba0bda7f8
@ -8,7 +8,9 @@ import (
|
|||||||
|
|
||||||
// 获取课程列表请求
|
// 获取课程列表请求
|
||||||
type LessonListReq struct {
|
type LessonListReq struct {
|
||||||
g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"`
|
g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"`
|
||||||
|
CategoryId int64 `json:"categoryId" dc:"分类ID"`
|
||||||
|
Tag string `json:"tag" dc:"标签"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取课程列表响应
|
// 获取课程列表响应
|
||||||
|
@ -12,17 +12,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *ControllerV1) LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) {
|
func (c *ControllerV1) LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) {
|
||||||
|
// 构建查询条件
|
||||||
|
query := dao.Lesson.Ctx(ctx)
|
||||||
|
|
||||||
|
// 按分类ID过滤
|
||||||
|
if req.CategoryId > 0 {
|
||||||
|
query = query.Where("category_id = ?", req.CategoryId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 按标签过滤
|
||||||
|
|
||||||
// 查询课程列表
|
// 查询课程列表
|
||||||
var list []*entity.Lesson
|
var list []*entity.Lesson
|
||||||
err = dao.Lesson.Ctx(ctx).Scan(&list)
|
err = query.Scan(&list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统计总数
|
// 统计总数
|
||||||
total, err := dao.Lesson.Ctx(ctx).Count()
|
total, err := query.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
res = &v1.LessonListRes{
|
res = &v1.LessonListRes{
|
||||||
List: list,
|
List: list,
|
||||||
Total: total,
|
Total: total,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user