feat: 🎸 课程章节接口
This commit is contained in:
parent
903e7ba861
commit
6771d3298f
@ -13,4 +13,6 @@ import (
|
|||||||
type ILessonV1 interface {
|
type ILessonV1 interface {
|
||||||
LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error)
|
LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error)
|
||||||
LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error)
|
LessonDetail(ctx context.Context, req *v1.LessonDetailReq) (res *v1.LessonDetailRes, err error)
|
||||||
|
LessonSectionList(ctx context.Context, req *v1.LessonSectionListReq) (res *v1.LessonSectionListRes, err error)
|
||||||
|
LessonSectionDetail(ctx context.Context, req *v1.LessonSectionDetailReq) (res *v1.LessonSectionDetailRes, err error)
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,28 @@ type LessonDetailReq struct {
|
|||||||
|
|
||||||
// 查看课程详情响应
|
// 查看课程详情响应
|
||||||
type LessonDetailRes struct {
|
type LessonDetailRes struct {
|
||||||
Lesson *entity.Lesson `json:"lesson" dc:"课程"`
|
*entity.Lesson `dc:"课程"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取课程章节列表请求
|
||||||
|
type LessonSectionListReq struct {
|
||||||
|
g.Meta `path:"/lesson/section/list" method:"get" tags:"课程章节" summary:"获取课程章节列表"`
|
||||||
|
LessonId int64 `json:"lessonId" v:"required#课程ID必填" dc:"课程ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取课程章节列表响应
|
||||||
|
type LessonSectionListRes struct {
|
||||||
|
List []*entity.LessonSection `json:"list" dc:"课程章节列表"`
|
||||||
|
Total int `json:"total" dc:"总数"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取课程章节详情请求
|
||||||
|
type LessonSectionDetailReq struct {
|
||||||
|
g.Meta `path:"/lesson/section/detail" method:"get" tags:"课程章节" summary:"获取课程章节详情"`
|
||||||
|
Id int64 `json:"id" v:"required#课程章节ID必填" dc:"课程章节ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取课程章节详情响应
|
||||||
|
type LessonSectionDetailRes struct {
|
||||||
|
*entity.LessonSection `dc:"课程章节"`
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"hotgo/internal/model/entity"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gcode"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
|
||||||
|
v1 "hotgo/api/api/lesson/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *ControllerV1) LessonSectionDetail(ctx context.Context, req *v1.LessonSectionDetailReq) (res *v1.LessonSectionDetailRes, err error) {
|
||||||
|
section := new(entity.LessonSection)
|
||||||
|
err = dao.LessonSection.Ctx(ctx).Where("id = ?", req.Id).Scan(section)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||||
|
}
|
||||||
|
if section.Id == 0 {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeNotFound, "课程章节不存在")
|
||||||
|
}
|
||||||
|
res = &v1.LessonSectionDetailRes{
|
||||||
|
LessonSection: section,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package lesson
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"hotgo/internal/model/entity"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/errors/gcode"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
|
||||||
|
v1 "hotgo/api/api/lesson/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *ControllerV1) LessonSectionList(ctx context.Context, req *v1.LessonSectionListReq) (res *v1.LessonSectionListRes, err error) {
|
||||||
|
var list []*entity.LessonSection
|
||||||
|
err = dao.LessonSection.Ctx(ctx).Where("lesson_id = ?", req.LessonId).Scan(&list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||||
|
}
|
||||||
|
total, err := dao.LessonSection.Ctx(ctx).Where("lesson_id = ?", req.LessonId).Count()
|
||||||
|
if err != nil {
|
||||||
|
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
||||||
|
}
|
||||||
|
res = &v1.LessonSectionListRes{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user