diff --git a/server/api/api/lesson/lesson.go b/server/api/api/lesson/lesson.go index 5aac3d5..2b1db55 100644 --- a/server/api/api/lesson/lesson.go +++ b/server/api/api/lesson/lesson.go @@ -13,4 +13,6 @@ import ( type ILessonV1 interface { LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, 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) } diff --git a/server/api/api/lesson/v1/lesson.go b/server/api/api/lesson/v1/lesson.go index df5ea1d..f76843e 100644 --- a/server/api/api/lesson/v1/lesson.go +++ b/server/api/api/lesson/v1/lesson.go @@ -25,5 +25,28 @@ type LessonDetailReq 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:"课程章节"` } diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go b/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go new file mode 100644 index 0000000..a758b6d --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go @@ -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 +} diff --git a/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go b/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go new file mode 100644 index 0000000..bb16fb3 --- /dev/null +++ b/server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go @@ -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 +}