添加课程内容sql和api
This commit is contained in:
105
server/api/course_content.api
Normal file
105
server/api/course_content.api
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
11
server/sql/course_content.sql
Normal file
11
server/sql/course_content.sql
Normal file
@@ -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='课程内容表(章节/小节)';
|
||||||
Reference in New Issue
Block a user