From 44857aed750e282e3ee3d08604f904f7ea2c79a9 Mon Sep 17 00:00:00 2001 From: mayiming <1627832236@qq.com> Date: Fri, 31 Oct 2025 13:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B=E5=86=85?= =?UTF-8?q?=E5=AE=B9sql=E5=92=8Capi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/course_content.api | 105 ++++++++++++++++++++++++++++++++++ server/sql/course_content.sql | 11 ++++ 2 files changed, 116 insertions(+) create mode 100644 server/api/course_content.api create mode 100644 server/sql/course_content.sql diff --git a/server/api/course_content.api b/server/api/course_content.api new file mode 100644 index 00000000..71f0f97e --- /dev/null +++ b/server/api/course_content.api @@ -0,0 +1,105 @@ +// 课程内容请求和响应类型定义 +type CourseContent { + Id int `json:"id"` // 内容ID(主键) + CourseId int `json:"course_id"` // 关联课程ID + ParentId int `json:"parent_id"` // 父级ID(0表示章节,>0表示小节) + Title string `json:"title"` // 章节/小节标题 + Content string `json:"content"` // 内容详情 + Sort int `json:"sort"` // 排序 +} + +// 基础响应结构 +type BaseResp { + Code int `json:"code"` // 状态码,0表示成功 + Message string `json:"message"` // 提示信息 + Data interface{} `json:"data"` // 响应数据 +} + +// 获取课程内容列表请求 +type GetContentListReq { + CourseId int `json:"course_id" form:"course_id"` // 课程ID,必填 + ParentId int `json:"parent_id" form:"parent_id"` // 父级ID,可选,0表示获取章节 +} + +// 获取课程内容列表响应 +type GetContentListResp { + BaseResp + Data []CourseContent `json:"data"` // 内容列表 +} + +// 获取单个内容详情请求 +type GetContentReq { + Id int `json:"id" form:"id" uri:"id"` // 内容ID,必填 +} + +// 获取单个内容详情响应 +type GetContentResp { + BaseResp + Data CourseContent `json:"data"` // 内容详情 +} + +// 新增内容请求 +type AddContentReq { + CourseId int `json:"course_id" form:"course_id"` // 课程ID,必填 + ParentId int `json:"parent_id" form:"parent_id"` // 父级ID,必填 + Title string `json:"title" form:"title"` // 标题,必填 + Content string `json:"content" form:"content"` // 内容详情,可选 + Sort int `json:"sort" form:"sort"` // 排序,可选 +} + +// 新增内容响应 +type AddContentResp { + BaseResp + Data int `json:"data"` // 新增内容的ID +} + +// 更新内容请求 +type UpdateContentReq { + Id int `json:"id" form:"id"` // 内容ID,必填 + Title string `json:"title" form:"title"` // 标题,可选 + Content string `json:"content" form:"content"` // 内容详情,可选 + Sort int `json:"sort" form:"sort"` // 排序,可选 +} + +// 更新内容响应 +type UpdateContentResp { + BaseResp +} + +// 删除内容请求 +type DeleteContentReq { + Id int `json:"id" form:"id" uri:"id"` // 内容ID,必填 +} + +// 删除内容响应 +type DeleteContentResp { + BaseResp +} + +// 课程内容API服务 +@server ( + group: course_content + prefix: /api/course-content +) +service course_content_api { + // 获取课程内容列表 + @handler GetContentListHandler + get /api/course-content/list (GetContentListReq) returns (GetContentListResp) + + // 获取单个内容详情 + @handler GetContentHandler + get /api/course-content/:id (GetContentReq) returns (GetContentResp) + + // 新增内容 + @handler AddContentHandler + post /api/course-content (AddContentReq) returns (AddContentResp) + + // 更新内容 + @handler UpdateContentHandler + put /api/course-content (UpdateContentReq) returns (UpdateContentResp) + + // 删除内容 + @handler DeleteContentHandler + delete /api/course-content/:id (DeleteContentReq) returns (DeleteContentResp) +} + diff --git a/server/sql/course_content.sql b/server/sql/course_content.sql new file mode 100644 index 00000000..084b5c75 --- /dev/null +++ b/server/sql/course_content.sql @@ -0,0 +1,11 @@ +CREATE TABLE `course_content` ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '内容ID(主键)', + `course_id` int NOT NULL COMMENT '关联课程ID', + `parent_id` int DEFAULT 0 COMMENT '父级ID(0表示章节,>0表示小节,关联自身id)', + `title` varchar(255) NOT NULL COMMENT '章节/小节标题', + `content` text COMMENT '内容详情(如视频地址、图文内容等)', + `sort` int DEFAULT 0 COMMENT '排序(数字越小越靠前)', + PRIMARY KEY (`id`), + KEY `idx_course_id` (`course_id`) COMMENT '按课程查询内容', + KEY `idx_parent_id` (`parent_id`) COMMENT '按父级查询子内容' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='课程内容表(章节/小节)'; \ No newline at end of file