yl 59d31d4b47 feat: 添加我的课程模块功能
- 新增我的课程列表API接口
- 支持按学习状态筛选(全部/学习中/已完结)
- 支持分页查询
- 包含课程基本信息、学习进度等数据
- 添加Apifox接口文档配置指南

文件变更:
- server/api/admin/mycourse/mycourse.go - API接口定义
- server/internal/controller/admin/mycourse/mycourse.go - 控制器层
- server/internal/service/mycourse.go - 服务层(模拟数据)
- server/internal/router/admin.go - 路由配置
- docs/apifox_config.md - 接口文档
2025-07-28 15:30:04 +08:00

107 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package service
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Yl <yl@example.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package service
import (
"context"
"hotgo/api/admin/mycourse"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
)
type sMyCourse struct{}
func init() {
service := &sMyCourse{}
if err := gconv.Struct(service, &MyCourse); err != nil {
g.Log().Fatal(context.TODO(), err)
}
}
func MyCourse() *sMyCourse {
return &sMyCourse{}
}
// List 获取我的课程列表(模拟数据)
func (s *sMyCourse) List(ctx context.Context, userId uint64, req *mycourse.MyCourseListReq) (list []*mycourse.MyCourseListModel, totalCount int, err error) {
// 模拟数据 - 根据截图内容
mockData := []*mycourse.MyCourseListModel{
{
Id: 1,
CourseId: 1,
Title: "教育心理学的起源",
Subtitle: "计算机二级考前直播",
CoverImage: "/uploads/course/cover1.jpg",
Instructor: "代万权",
Subject: "史学",
Description: "本课程紧跟风向让每一位数据了解数据分析使用DeepSeek结合办公自动化职业岗位标准以实际工作任务为导向强调课程内容的实用性和针对性课程内容紧贴全国计算机等级考试技能。",
TotalEpisodes: 9,
TotalLessons: 54,
TotalDuration: "12小时43分钟",
StudiedDuration: "10小时20分钟",
StudyStatus: 1,
StudyStatusText: "学习中",
EnrollmentTime: gtime.New("2025-01-20 10:30:00"),
},
{
Id: 2,
CourseId: 2,
Title: "数据分析基础",
Subtitle: "Python数据分析入门",
CoverImage: "/uploads/course/cover2.jpg",
Instructor: "张老师",
Subject: "计算机",
Description: "从零开始学习Python数据分析掌握pandas、numpy等核心库的使用方法。",
TotalEpisodes: 8,
TotalLessons: 32,
TotalDuration: "16小时",
StudiedDuration: "16小时",
StudyStatus: 2,
StudyStatusText: "已完结",
EnrollmentTime: gtime.New("2025-01-15 09:00:00"),
},
}
// 根据学习状态筛选
if req.StudyStatus > 0 {
var filteredData []*mycourse.MyCourseListModel
for _, item := range mockData {
if item.StudyStatus == req.StudyStatus {
filteredData = append(filteredData, item)
}
}
mockData = filteredData
}
totalCount = len(mockData)
// 分页处理
pageNum := req.Page
pageSize := req.Size
if pageNum <= 0 {
pageNum = 1
}
if pageSize <= 0 {
pageSize = 10
}
start := (pageNum - 1) * pageSize
end := start + pageSize
if start >= totalCount {
list = []*mycourse.MyCourseListModel{}
return
}
if end > totalCount {
end = totalCount
}
list = mockData[start:end]
return
}