From 6771d3298ff452f0410fd91e101e5828092e5127 Mon Sep 17 00:00:00 2001 From: GoCo Date: Fri, 25 Jul 2025 17:02:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/api/lesson/lesson.go | 2 ++ server/api/api/lesson/v1/lesson.go | 25 +++++++++++++++- .../lesson/lesson_v1_lesson_section_detail.go | 28 +++++++++++++++++ .../lesson/lesson_v1_lesson_section_list.go | 30 +++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_section_detail.go create mode 100644 server/internal/controller/api/lesson/lesson_v1_lesson_section_list.go 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 +}