1
This commit is contained in:
@@ -2,12 +2,14 @@ package v1
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/learning"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
|
||||
)
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
LearningApiGroup learning.ApiGroup
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ChapterApi struct{}
|
||||
|
||||
// CreateChapter 创建章节
|
||||
// @Tags Chapter
|
||||
// @Summary 创建章节
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.ChapterCreate true "创建章节"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /chapter/createChapter [post]
|
||||
func (chapterApi *ChapterApi) CreateChapter(c *gin.Context) {
|
||||
var req learningReq.ChapterCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
chapter := learning.Chapter{
|
||||
CourseId: req.CourseId,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Sort: req.Sort,
|
||||
Status: req.Status,
|
||||
Duration: req.Duration,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.ChapterService.CreateChapter(c.Request.Context(), &chapter)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteChapter 删除章节
|
||||
// @Tags Chapter
|
||||
// @Summary 删除章节
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除章节"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /chapter/deleteChapter [delete]
|
||||
func (chapterApi *ChapterApi) DeleteChapter(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.ChapterService.DeleteChapter(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteChapterByIds 批量删除章节
|
||||
// @Tags Chapter
|
||||
// @Summary 批量删除章节
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /chapter/deleteChapterByIds [delete]
|
||||
func (chapterApi *ChapterApi) DeleteChapterByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.ChapterService.DeleteChapterByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateChapter 更新章节
|
||||
// @Tags Chapter
|
||||
// @Summary 更新章节
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.ChapterUpdate true "更新章节"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /chapter/updateChapter [put]
|
||||
func (chapterApi *ChapterApi) UpdateChapter(c *gin.Context) {
|
||||
var req learningReq.ChapterUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
chapter := learning.Chapter{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
CourseId: req.CourseId,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Sort: req.Sort,
|
||||
Status: req.Status,
|
||||
Duration: req.Duration,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.ChapterService.UpdateChapter(c.Request.Context(), chapter)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindChapter 用id查询章节
|
||||
// @Tags Chapter
|
||||
// @Summary 用id查询章节
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.Chapter true "用id查询章节"
|
||||
// @Success 200 {object} response.Response{data=learning.Chapter,msg=string} "查询成功"
|
||||
// @Router /chapter/findChapter [get]
|
||||
func (chapterApi *ChapterApi) FindChapter(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
rechapter, err := service.ServiceGroupApp.LearningServiceGroup.ChapterService.GetChapter(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(rechapter, c)
|
||||
}
|
||||
|
||||
// GetChapterList 分页获取章节列表
|
||||
// @Tags Chapter
|
||||
// @Summary 分页获取章节列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.ChapterSearch true "分页获取章节列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /chapter/getChapterList [get]
|
||||
func (chapterApi *ChapterApi) GetChapterList(c *gin.Context) {
|
||||
var pageInfo learningReq.ChapterSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.ChapterService.GetChapterInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetChaptersByCourse 根据课程获取章节列表
|
||||
// @Tags Chapter
|
||||
// @Summary 根据课程获取章节列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param courseId query uint true "课程ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.Chapter,msg=string} "获取成功"
|
||||
// @Router /chapter/getChaptersByCourse [get]
|
||||
func (chapterApi *ChapterApi) GetChaptersByCourse(c *gin.Context) {
|
||||
courseIdStr := c.Query("courseId")
|
||||
courseId, err := strconv.ParseUint(courseIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("课程ID格式错误", c)
|
||||
return
|
||||
}
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.ChapterService.GetChaptersByCourse(c.Request.Context(), uint(courseId))
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type CourseApi struct{}
|
||||
|
||||
// CreateCourse 创建课程
|
||||
// @Tags Course
|
||||
// @Summary 创建课程
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.CourseCreate true "创建课程"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /course/createCourse [post]
|
||||
func (courseApi *CourseApi) CreateCourse(c *gin.Context) {
|
||||
var req learningReq.CourseCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
course := learning.Course{
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Cover: req.Cover,
|
||||
Difficulty: req.Difficulty,
|
||||
Duration: req.Duration,
|
||||
Status: req.Status,
|
||||
Price: req.Price,
|
||||
Tags: req.Tags,
|
||||
Sort: req.Sort,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.CourseService.CreateCourse(c.Request.Context(), &course)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteCourse 删除课程
|
||||
// @Tags Course
|
||||
// @Summary 删除课程
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除课程"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /course/deleteCourse [delete]
|
||||
func (courseApi *CourseApi) DeleteCourse(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.CourseService.DeleteCourse(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteCourseByIds 批量删除课程
|
||||
// @Tags Course
|
||||
// @Summary 批量删除课程
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /course/deleteCourseByIds [delete]
|
||||
func (courseApi *CourseApi) DeleteCourseByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.CourseService.DeleteCourseByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateCourse 更新课程
|
||||
// @Tags Course
|
||||
// @Summary 更新课程
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.CourseUpdate true "更新课程"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /course/updateCourse [put]
|
||||
func (courseApi *CourseApi) UpdateCourse(c *gin.Context) {
|
||||
var req learningReq.CourseUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
course := learning.Course{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
Cover: req.Cover,
|
||||
Difficulty: req.Difficulty,
|
||||
Duration: req.Duration,
|
||||
Status: req.Status,
|
||||
Price: req.Price,
|
||||
Tags: req.Tags,
|
||||
Sort: req.Sort,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.CourseService.UpdateCourse(c.Request.Context(), course)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindCourse 用id查询课程
|
||||
// @Tags Course
|
||||
// @Summary 用id查询课程
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.Course true "用id查询课程"
|
||||
// @Success 200 {object} response.Response{data=learning.Course,msg=string} "查询成功"
|
||||
// @Router /course/findCourse [get]
|
||||
func (courseApi *CourseApi) FindCourse(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
recourse, err := service.ServiceGroupApp.LearningServiceGroup.CourseService.GetCourse(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(recourse, c)
|
||||
}
|
||||
|
||||
// GetCourseList 分页获取课程列表
|
||||
// @Tags Course
|
||||
// @Summary 分页获取课程列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.CourseSearch true "分页获取课程列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /course/getCourseList [get]
|
||||
func (courseApi *CourseApi) GetCourseList(c *gin.Context) {
|
||||
var pageInfo learningReq.CourseSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.CourseService.GetCourseInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetPublishedCourses 获取已发布的课程列表
|
||||
// @Tags Course
|
||||
// @Summary 获取已发布的课程列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=[]learning.Course,msg=string} "获取成功"
|
||||
// @Router /course/getPublishedCourses [get]
|
||||
func (courseApi *CourseApi) GetPublishedCourses(c *gin.Context) {
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.CourseService.GetPublishedCourses(c.Request.Context())
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package learning
|
||||
|
||||
type ApiGroup struct {
|
||||
CourseApi
|
||||
ChapterApi
|
||||
KnowledgePointApi
|
||||
QuestionApi
|
||||
UserLearningApi
|
||||
WrongQuestionApi
|
||||
ExamApi
|
||||
UserExamApi
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ExamApi struct{}
|
||||
|
||||
// CreateExam 创建考试
|
||||
// @Tags Exam
|
||||
// @Summary 创建考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.ExamCreate true "创建考试"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /exam/createExam [post]
|
||||
func (examApi *ExamApi) CreateExam(c *gin.Context) {
|
||||
var req learningReq.ExamCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
exam := learning.Exam{
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
CourseId: req.CourseId,
|
||||
Duration: req.Duration,
|
||||
TotalScore: req.TotalScore,
|
||||
PassScore: req.PassScore,
|
||||
QuestionCount: req.QuestionCount,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
Status: req.Status,
|
||||
AllowRetake: req.AllowRetake,
|
||||
MaxAttempts: req.MaxAttempts,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.ExamService.CreateExam(c.Request.Context(), &exam)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteExam 删除考试
|
||||
// @Tags Exam
|
||||
// @Summary 删除考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除考试"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /exam/deleteExam [delete]
|
||||
func (examApi *ExamApi) DeleteExam(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.ExamService.DeleteExam(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteExamByIds 批量删除考试
|
||||
// @Tags Exam
|
||||
// @Summary 批量删除考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /exam/deleteExamByIds [delete]
|
||||
func (examApi *ExamApi) DeleteExamByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.ExamService.DeleteExamByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateExam 更新考试
|
||||
// @Tags Exam
|
||||
// @Summary 更新考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.ExamUpdate true "更新考试"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /exam/updateExam [put]
|
||||
func (examApi *ExamApi) UpdateExam(c *gin.Context) {
|
||||
var req learningReq.ExamUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
exam := learning.Exam{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
CourseId: req.CourseId,
|
||||
Duration: req.Duration,
|
||||
TotalScore: req.TotalScore,
|
||||
PassScore: req.PassScore,
|
||||
QuestionCount: req.QuestionCount,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
Status: req.Status,
|
||||
AllowRetake: req.AllowRetake,
|
||||
MaxAttempts: req.MaxAttempts,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.ExamService.UpdateExam(c.Request.Context(), exam)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindExam 用id查询考试
|
||||
// @Tags Exam
|
||||
// @Summary 用id查询考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.Exam true "用id查询考试"
|
||||
// @Success 200 {object} response.Response{data=learning.Exam,msg=string} "查询成功"
|
||||
// @Router /exam/findExam [get]
|
||||
func (examApi *ExamApi) FindExam(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
reexam, err := service.ServiceGroupApp.LearningServiceGroup.ExamService.GetExam(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(reexam, c)
|
||||
}
|
||||
|
||||
// GetExamList 分页获取考试列表
|
||||
// @Tags Exam
|
||||
// @Summary 分页获取考试列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.ExamSearch true "分页获取考试列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /exam/getExamList [get]
|
||||
func (examApi *ExamApi) GetExamList(c *gin.Context) {
|
||||
var pageInfo learningReq.ExamSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.ExamService.GetExamInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetActiveExams 获取进行中的考试列表
|
||||
// @Tags Exam
|
||||
// @Summary 获取进行中的考试列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=[]learning.Exam,msg=string} "获取成功"
|
||||
// @Router /exam/getActiveExams [get]
|
||||
func (examApi *ExamApi) GetActiveExams(c *gin.Context) {
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.ExamService.GetActiveExams(c.Request.Context())
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// GetExamsByCourse 根据课程获取考试列表
|
||||
// @Tags Exam
|
||||
// @Summary 根据课程获取考试列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param courseId query uint true "课程ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.Exam,msg=string} "获取成功"
|
||||
// @Router /exam/getExamsByCourse [get]
|
||||
func (examApi *ExamApi) GetExamsByCourse(c *gin.Context) {
|
||||
courseIdStr := c.Query("courseId")
|
||||
courseId := uint(0)
|
||||
if courseIdStr != "" {
|
||||
if id, err := strconv.ParseUint(courseIdStr, 10, 32); err == nil {
|
||||
courseId = uint(id)
|
||||
}
|
||||
}
|
||||
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.ExamService.GetExamsByCourse(c.Request.Context(), courseId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// PublishExam 发布考试
|
||||
// @Tags Exam
|
||||
// @Summary 发布考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.PublishExamRequest true "发布考试请求"
|
||||
// @Success 200 {object} response.Response{msg=string} "发布成功"
|
||||
// @Router /exam/publishExam [put]
|
||||
func (examApi *ExamApi) PublishExam(c *gin.Context) {
|
||||
var req learningReq.PublishExamRequest
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.ExamService.PublishExam(c.Request.Context(), req.ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("发布失败!", zap.Error(err))
|
||||
response.FailWithMessage("发布失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("发布成功", c)
|
||||
}
|
||||
|
||||
// GetExamStatistics 获取考试统计
|
||||
// @Tags Exam
|
||||
// @Summary 获取考试统计
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=learningReq.ExamStatistics,msg=string} "获取成功"
|
||||
// @Router /exam/getExamStatistics [get]
|
||||
func (examApi *ExamApi) GetExamStatistics(c *gin.Context) {
|
||||
stats, err := service.ServiceGroupApp.LearningServiceGroup.ExamService.GetExamStatistics(c.Request.Context())
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(stats, c)
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type KnowledgePointApi struct{}
|
||||
|
||||
// CreateKnowledgePoint 创建知识点
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 创建知识点
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.KnowledgePointCreate true "创建知识点"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /knowledgePoint/createKnowledgePoint [post]
|
||||
func (knowledgePointApi *KnowledgePointApi) CreateKnowledgePoint(c *gin.Context) {
|
||||
var req learningReq.KnowledgePointCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
knowledgePoint := learning.KnowledgePoint{
|
||||
ChapterId: req.ChapterId,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
VideoUrl: req.VideoUrl,
|
||||
Attachments: req.Attachments,
|
||||
Sort: req.Sort,
|
||||
Duration: req.Duration,
|
||||
Status: req.Status,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.CreateKnowledgePoint(c.Request.Context(), &knowledgePoint)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteKnowledgePoint 删除知识点
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 删除知识点
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除知识点"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /knowledgePoint/deleteKnowledgePoint [delete]
|
||||
func (knowledgePointApi *KnowledgePointApi) DeleteKnowledgePoint(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.DeleteKnowledgePoint(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteKnowledgePointByIds 批量删除知识点
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 批量删除知识点
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /knowledgePoint/deleteKnowledgePointByIds [delete]
|
||||
func (knowledgePointApi *KnowledgePointApi) DeleteKnowledgePointByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.DeleteKnowledgePointByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateKnowledgePoint 更新知识点
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 更新知识点
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.KnowledgePointUpdate true "更新知识点"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /knowledgePoint/updateKnowledgePoint [put]
|
||||
func (knowledgePointApi *KnowledgePointApi) UpdateKnowledgePoint(c *gin.Context) {
|
||||
var req learningReq.KnowledgePointUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
knowledgePoint := learning.KnowledgePoint{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
ChapterId: req.ChapterId,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
VideoUrl: req.VideoUrl,
|
||||
Attachments: req.Attachments,
|
||||
Sort: req.Sort,
|
||||
Duration: req.Duration,
|
||||
Status: req.Status,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.UpdateKnowledgePoint(c.Request.Context(), knowledgePoint)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindKnowledgePoint 用id查询知识点
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 用id查询知识点
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.KnowledgePoint true "用id查询知识点"
|
||||
// @Success 200 {object} response.Response{data=learning.KnowledgePoint,msg=string} "查询成功"
|
||||
// @Router /knowledgePoint/findKnowledgePoint [get]
|
||||
func (knowledgePointApi *KnowledgePointApi) FindKnowledgePoint(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
reknowledgePoint, err := service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.GetKnowledgePoint(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(reknowledgePoint, c)
|
||||
}
|
||||
|
||||
// GetKnowledgePointList 分页获取知识点列表
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 分页获取知识点列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.KnowledgePointSearch true "分页获取知识点列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /knowledgePoint/getKnowledgePointList [get]
|
||||
func (knowledgePointApi *KnowledgePointApi) GetKnowledgePointList(c *gin.Context) {
|
||||
var pageInfo learningReq.KnowledgePointSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.GetKnowledgePointInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetKnowledgePointsByChapter 根据章节获取知识点列表
|
||||
// @Tags KnowledgePoint
|
||||
// @Summary 根据章节获取知识点列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param chapterId query uint true "章节ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.KnowledgePoint,msg=string} "获取成功"
|
||||
// @Router /knowledgePoint/getKnowledgePointsByChapter [get]
|
||||
func (knowledgePointApi *KnowledgePointApi) GetKnowledgePointsByChapter(c *gin.Context) {
|
||||
chapterIdStr := c.Query("chapterId")
|
||||
chapterId, err := strconv.ParseUint(chapterIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("章节ID格式错误", c)
|
||||
return
|
||||
}
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.KnowledgePointService.GetKnowledgePointsByChapter(c.Request.Context(), uint(chapterId))
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type QuestionApi struct{}
|
||||
|
||||
// CreateQuestion 创建题目
|
||||
// @Tags Question
|
||||
// @Summary 创建题目
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.QuestionCreate true "创建题目"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /question/createQuestion [post]
|
||||
func (questionApi *QuestionApi) CreateQuestion(c *gin.Context) {
|
||||
var req learningReq.QuestionCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
question := learning.Question{
|
||||
KnowledgePointId: req.KnowledgePointId,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
Type: req.Type,
|
||||
Options: req.Options,
|
||||
Answer: req.Answer,
|
||||
Explanation: req.Explanation,
|
||||
Difficulty: req.Difficulty,
|
||||
Score: req.Score,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.QuestionService.CreateQuestion(c.Request.Context(), &question)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteQuestion 删除题目
|
||||
// @Tags Question
|
||||
// @Summary 删除题目
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除题目"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /question/deleteQuestion [delete]
|
||||
func (questionApi *QuestionApi) DeleteQuestion(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.QuestionService.DeleteQuestion(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteQuestionByIds 批量删除题目
|
||||
// @Tags Question
|
||||
// @Summary 批量删除题目
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /question/deleteQuestionByIds [delete]
|
||||
func (questionApi *QuestionApi) DeleteQuestionByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.QuestionService.DeleteQuestionByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateQuestion 更新题目
|
||||
// @Tags Question
|
||||
// @Summary 更新题目
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.QuestionUpdate true "更新题目"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /question/updateQuestion [put]
|
||||
func (questionApi *QuestionApi) UpdateQuestion(c *gin.Context) {
|
||||
var req learningReq.QuestionUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
question := learning.Question{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
KnowledgePointId: req.KnowledgePointId,
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
Type: req.Type,
|
||||
Options: req.Options,
|
||||
Answer: req.Answer,
|
||||
Explanation: req.Explanation,
|
||||
Difficulty: req.Difficulty,
|
||||
Score: req.Score,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.QuestionService.UpdateQuestion(c.Request.Context(), question)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindQuestion 用id查询题目
|
||||
// @Tags Question
|
||||
// @Summary 用id查询题目
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.Question true "用id查询题目"
|
||||
// @Success 200 {object} response.Response{data=learning.Question,msg=string} "查询成功"
|
||||
// @Router /question/findQuestion [get]
|
||||
func (questionApi *QuestionApi) FindQuestion(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
requestion, err := service.ServiceGroupApp.LearningServiceGroup.QuestionService.GetQuestion(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(requestion, c)
|
||||
}
|
||||
|
||||
// GetQuestionList 分页获取题目列表
|
||||
// @Tags Question
|
||||
// @Summary 分页获取题目列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.QuestionSearch true "分页获取题目列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /question/getQuestionList [get]
|
||||
func (questionApi *QuestionApi) GetQuestionList(c *gin.Context) {
|
||||
var pageInfo learningReq.QuestionSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.QuestionService.GetQuestionInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetQuestionsByKnowledgePoint 根据知识点获取题目列表
|
||||
// @Tags Question
|
||||
// @Summary 根据知识点获取题目列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param knowledgePointId query uint true "知识点ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.Question,msg=string} "获取成功"
|
||||
// @Router /question/getQuestionsByKnowledgePoint [get]
|
||||
func (questionApi *QuestionApi) GetQuestionsByKnowledgePoint(c *gin.Context) {
|
||||
knowledgePointIdStr := c.Query("knowledgePointId")
|
||||
knowledgePointId, err := strconv.ParseUint(knowledgePointIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("知识点ID格式错误", c)
|
||||
return
|
||||
}
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.QuestionService.GetQuestionsByKnowledgePoint(c.Request.Context(), uint(knowledgePointId))
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type UserExamApi struct{}
|
||||
|
||||
// CreateUserExam 创建用户考试记录
|
||||
// @Tags UserExam
|
||||
// @Summary 创建用户考试记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.UserExamCreate true "创建用户考试记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /userExam/createUserExam [post]
|
||||
func (userExamApi *UserExamApi) CreateUserExam(c *gin.Context) {
|
||||
var req learningReq.UserExamCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
userExam := learning.UserExam{
|
||||
UserId: req.UserId,
|
||||
ExamId: req.ExamId,
|
||||
AttemptNumber: req.AttemptNumber,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
Duration: req.Duration,
|
||||
TotalScore: req.TotalScore,
|
||||
CorrectCount: req.CorrectCount,
|
||||
WrongCount: req.WrongCount,
|
||||
Status: req.Status,
|
||||
IsPassed: req.IsPassed,
|
||||
SubmittedAt: req.SubmittedAt,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.UserExamService.CreateUserExam(c.Request.Context(), &userExam)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteUserExam 删除用户考试记录
|
||||
// @Tags UserExam
|
||||
// @Summary 删除用户考试记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除用户考试记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /userExam/deleteUserExam [delete]
|
||||
func (userExamApi *UserExamApi) DeleteUserExam(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.DeleteUserExam(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteUserExamByIds 批量删除用户考试记录
|
||||
// @Tags UserExam
|
||||
// @Summary 批量删除用户考试记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /userExam/deleteUserExamByIds [delete]
|
||||
func (userExamApi *UserExamApi) DeleteUserExamByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.DeleteUserExamByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateUserExam 更新用户考试记录
|
||||
// @Tags UserExam
|
||||
// @Summary 更新用户考试记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.UserExamUpdate true "更新用户考试记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /userExam/updateUserExam [put]
|
||||
func (userExamApi *UserExamApi) UpdateUserExam(c *gin.Context) {
|
||||
var req learningReq.UserExamUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
userExam := learning.UserExam{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
UserId: req.UserId,
|
||||
ExamId: req.ExamId,
|
||||
AttemptNumber: req.AttemptNumber,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
Duration: req.Duration,
|
||||
TotalScore: req.TotalScore,
|
||||
CorrectCount: req.CorrectCount,
|
||||
WrongCount: req.WrongCount,
|
||||
Status: req.Status,
|
||||
IsPassed: req.IsPassed,
|
||||
SubmittedAt: req.SubmittedAt,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.UserExamService.UpdateUserExam(c.Request.Context(), userExam)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindUserExam 用id查询用户考试记录
|
||||
// @Tags UserExam
|
||||
// @Summary 用id查询用户考试记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.UserExam true "用id查询用户考试记录"
|
||||
// @Success 200 {object} response.Response{data=learning.UserExam,msg=string} "查询成功"
|
||||
// @Router /userExam/findUserExam [get]
|
||||
func (userExamApi *UserExamApi) FindUserExam(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
reuserExam, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.GetUserExam(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(reuserExam, c)
|
||||
}
|
||||
|
||||
// GetUserExamList 分页获取用户考试记录列表
|
||||
// @Tags UserExam
|
||||
// @Summary 分页获取用户考试记录列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.UserExamSearch true "分页获取用户考试记录列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /userExam/getUserExamList [get]
|
||||
func (userExamApi *UserExamApi) GetUserExamList(c *gin.Context) {
|
||||
var pageInfo learningReq.UserExamSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.GetUserExamInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// StartExam 开始考试
|
||||
// @Tags UserExam
|
||||
// @Summary 开始考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.StartExamRequest true "开始考试请求"
|
||||
// @Success 200 {object} response.Response{data=learning.UserExam,msg=string} "开始成功"
|
||||
// @Router /userExam/startExam [post]
|
||||
func (userExamApi *UserExamApi) StartExam(c *gin.Context) {
|
||||
var req learningReq.StartExamRequest
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
if req.UserId == 0 {
|
||||
req.UserId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
userExam, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.StartExam(c.Request.Context(), req.UserId, req.ExamId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("开始考试失败!", zap.Error(err))
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(userExam, c)
|
||||
}
|
||||
|
||||
// SubmitExam 提交考试
|
||||
// @Tags UserExam
|
||||
// @Summary 提交考试
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.SubmitExamRequest true "提交考试请求"
|
||||
// @Success 200 {object} response.Response{msg=string} "提交成功"
|
||||
// @Router /userExam/submitExam [put]
|
||||
func (userExamApi *UserExamApi) SubmitExam(c *gin.Context) {
|
||||
var req learningReq.SubmitExamRequest
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.UserExamService.SubmitExam(c.Request.Context(), req.UserExamId, req.TotalScore, req.CorrectCount, req.WrongCount)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("提交考试失败!", zap.Error(err))
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("提交成功", c)
|
||||
}
|
||||
|
||||
// GetUserExamHistory 获取用户考试历史
|
||||
// @Tags UserExam
|
||||
// @Summary 获取用户考试历史
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint false "用户ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.UserExam,msg=string} "获取成功"
|
||||
// @Router /userExam/getUserExamHistory [get]
|
||||
func (userExamApi *UserExamApi) GetUserExamHistory(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
|
||||
var userId uint
|
||||
if userIdStr != "" {
|
||||
userIdUint, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
userId = uint(userIdUint)
|
||||
} else {
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
userId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.GetUserExamHistory(c.Request.Context(), userId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// GetUserExamStatistics 获取用户考试统计
|
||||
// @Tags UserExam
|
||||
// @Summary 获取用户考试统计
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint false "用户ID"
|
||||
// @Success 200 {object} response.Response{data=learningReq.UserExamStatistics,msg=string} "获取成功"
|
||||
// @Router /userExam/getUserExamStatistics [get]
|
||||
func (userExamApi *UserExamApi) GetUserExamStatistics(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
|
||||
var userId uint
|
||||
if userIdStr != "" {
|
||||
userIdUint, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
userId = uint(userIdUint)
|
||||
} else {
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
userId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
stats, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.GetUserExamStatistics(c.Request.Context(), userId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(stats, c)
|
||||
}
|
||||
|
||||
// GetExamRanking 获取考试排行榜
|
||||
// @Tags UserExam
|
||||
// @Summary 获取考试排行榜
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param examId query uint true "考试ID"
|
||||
// @Param limit query int false "限制数量"
|
||||
// @Success 200 {object} response.Response{data=learningReq.ExamRankingResponse,msg=string} "获取成功"
|
||||
// @Router /userExam/getExamRanking [get]
|
||||
func (userExamApi *UserExamApi) GetExamRanking(c *gin.Context) {
|
||||
examIdStr := c.Query("examId")
|
||||
limitStr := c.Query("limit")
|
||||
|
||||
examId, err := strconv.ParseUint(examIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("考试ID格式错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
limit := 10 // 默认限制10条
|
||||
if limitStr != "" {
|
||||
if l, err := strconv.Atoi(limitStr); err == nil {
|
||||
limit = l
|
||||
}
|
||||
}
|
||||
|
||||
ranking, err := service.ServiceGroupApp.LearningServiceGroup.UserExamService.GetExamRanking(c.Request.Context(), uint(examId), limit)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(ranking, c)
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type UserLearningApi struct{}
|
||||
|
||||
// CreateUserLearning 创建用户学习记录
|
||||
// @Tags UserLearning
|
||||
// @Summary 创建用户学习记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.UserLearningCreate true "创建用户学习记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /userLearning/createUserLearning [post]
|
||||
func (userLearningApi *UserLearningApi) CreateUserLearning(c *gin.Context) {
|
||||
var req learningReq.UserLearningCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
userLearning := learning.UserLearning{
|
||||
UserId: req.UserId,
|
||||
CourseId: req.CourseId,
|
||||
ChapterId: req.ChapterId,
|
||||
KnowledgePointId: req.KnowledgePointId,
|
||||
Progress: req.Progress,
|
||||
StudyTime: req.StudyTime,
|
||||
LastStudyAt: req.LastStudyAt,
|
||||
Status: req.Status,
|
||||
Score: req.Score,
|
||||
CompletedAt: req.CompletedAt,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.UserLearningService.CreateUserLearning(c.Request.Context(), &userLearning)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteUserLearning 删除用户学习记录
|
||||
// @Tags UserLearning
|
||||
// @Summary 删除用户学习记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除用户学习记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /userLearning/deleteUserLearning [delete]
|
||||
func (userLearningApi *UserLearningApi) DeleteUserLearning(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.DeleteUserLearning(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteUserLearningByIds 批量删除用户学习记录
|
||||
// @Tags UserLearning
|
||||
// @Summary 批量删除用户学习记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /userLearning/deleteUserLearningByIds [delete]
|
||||
func (userLearningApi *UserLearningApi) DeleteUserLearningByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.DeleteUserLearningByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateUserLearning 更新用户学习记录
|
||||
// @Tags UserLearning
|
||||
// @Summary 更新用户学习记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.UserLearningUpdate true "更新用户学习记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /userLearning/updateUserLearning [put]
|
||||
func (userLearningApi *UserLearningApi) UpdateUserLearning(c *gin.Context) {
|
||||
var req learningReq.UserLearningUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
userLearning := learning.UserLearning{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
UserId: req.UserId,
|
||||
CourseId: req.CourseId,
|
||||
ChapterId: req.ChapterId,
|
||||
KnowledgePointId: req.KnowledgePointId,
|
||||
Progress: req.Progress,
|
||||
StudyTime: req.StudyTime,
|
||||
LastStudyAt: req.LastStudyAt,
|
||||
Status: req.Status,
|
||||
Score: req.Score,
|
||||
CompletedAt: req.CompletedAt,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.UserLearningService.UpdateUserLearning(c.Request.Context(), userLearning)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindUserLearning 用id查询用户学习记录
|
||||
// @Tags UserLearning
|
||||
// @Summary 用id查询用户学习记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.UserLearning true "用id查询用户学习记录"
|
||||
// @Success 200 {object} response.Response{data=learning.UserLearning,msg=string} "查询成功"
|
||||
// @Router /userLearning/findUserLearning [get]
|
||||
func (userLearningApi *UserLearningApi) FindUserLearning(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
reuserLearning, err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.GetUserLearning(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(reuserLearning, c)
|
||||
}
|
||||
|
||||
// GetUserLearningList 分页获取用户学习记录列表
|
||||
// @Tags UserLearning
|
||||
// @Summary 分页获取用户学习记录列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.UserLearningSearch true "分页获取用户学习记录列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /userLearning/getUserLearningList [get]
|
||||
func (userLearningApi *UserLearningApi) GetUserLearningList(c *gin.Context) {
|
||||
var pageInfo learningReq.UserLearningSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.GetUserLearningInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetUserProgress 获取用户学习进度
|
||||
// @Tags UserLearning
|
||||
// @Summary 获取用户学习进度
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint true "用户ID"
|
||||
// @Param courseId query uint false "课程ID"
|
||||
// @Success 200 {object} response.Response{data=[]learning.UserLearning,msg=string} "获取成功"
|
||||
// @Router /userLearning/getUserProgress [get]
|
||||
func (userLearningApi *UserLearningApi) GetUserProgress(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
courseIdStr := c.Query("courseId")
|
||||
|
||||
userId, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
var courseId uint = 0
|
||||
if courseIdStr != "" {
|
||||
courseIdUint, err := strconv.ParseUint(courseIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("课程ID格式错误", c)
|
||||
return
|
||||
}
|
||||
courseId = uint(courseIdUint)
|
||||
}
|
||||
|
||||
// 如果没有提供userId,尝试从JWT中获取当前用户ID
|
||||
if userId == 0 {
|
||||
userId = uint64(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.GetUserProgress(c.Request.Context(), uint(userId), courseId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// GetLearningStatistics 获取用户学习统计
|
||||
// @Tags UserLearning
|
||||
// @Summary 获取用户学习统计
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint false "用户ID"
|
||||
// @Success 200 {object} response.Response{data=learningReq.LearningStatistics,msg=string} "获取成功"
|
||||
// @Router /userLearning/getLearningStatistics [get]
|
||||
func (userLearningApi *UserLearningApi) GetLearningStatistics(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
|
||||
var userId uint
|
||||
if userIdStr != "" {
|
||||
userIdUint, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
userId = uint(userIdUint)
|
||||
} else {
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
userId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
stats, err := service.ServiceGroupApp.LearningServiceGroup.UserLearningService.GetLearningStatistics(c.Request.Context(), userId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(stats, c)
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
package learning
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/learning"
|
||||
learningReq "github.com/flipped-aurora/gin-vue-admin/server/model/learning/request"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type WrongQuestionApi struct{}
|
||||
|
||||
// CreateWrongQuestion 创建错题记录
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 创建错题记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.WrongQuestionCreate true "创建错题记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /wrongQuestion/createWrongQuestion [post]
|
||||
func (wrongQuestionApi *WrongQuestionApi) CreateWrongQuestion(c *gin.Context) {
|
||||
var req learningReq.WrongQuestionCreate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
wrongQuestion := learning.WrongQuestion{
|
||||
UserId: req.UserId,
|
||||
QuestionId: req.QuestionId,
|
||||
WrongAnswer: req.WrongAnswer,
|
||||
WrongCount: req.WrongCount,
|
||||
LastWrongAt: req.LastWrongAt,
|
||||
IsMastered: req.IsMastered,
|
||||
MasteredAt: req.MasteredAt,
|
||||
Notes: req.Notes,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.CreateWrongQuestion(c.Request.Context(), &wrongQuestion)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteWrongQuestion 删除错题记录
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 删除错题记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除错题记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /wrongQuestion/deleteWrongQuestion [delete]
|
||||
func (wrongQuestionApi *WrongQuestionApi) DeleteWrongQuestion(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.DeleteWrongQuestion(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteWrongQuestionByIds 批量删除错题记录
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 批量删除错题记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /wrongQuestion/deleteWrongQuestionByIds [delete]
|
||||
func (wrongQuestionApi *WrongQuestionApi) DeleteWrongQuestionByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.DeleteWrongQuestionByIds(c.Request.Context(), IDs)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateWrongQuestion 更新错题记录
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 更新错题记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.WrongQuestionUpdate true "更新错题记录"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /wrongQuestion/updateWrongQuestion [put]
|
||||
func (wrongQuestionApi *WrongQuestionApi) UpdateWrongQuestion(c *gin.Context) {
|
||||
var req learningReq.WrongQuestionUpdate
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
wrongQuestion := learning.WrongQuestion{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: req.ID},
|
||||
UserId: req.UserId,
|
||||
QuestionId: req.QuestionId,
|
||||
WrongAnswer: req.WrongAnswer,
|
||||
WrongCount: req.WrongCount,
|
||||
LastWrongAt: req.LastWrongAt,
|
||||
IsMastered: req.IsMastered,
|
||||
MasteredAt: req.MasteredAt,
|
||||
Notes: req.Notes,
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.UpdateWrongQuestion(c.Request.Context(), wrongQuestion)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindWrongQuestion 用id查询错题记录
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 用id查询错题记录
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learning.WrongQuestion true "用id查询错题记录"
|
||||
// @Success 200 {object} response.Response{data=learning.WrongQuestion,msg=string} "查询成功"
|
||||
// @Router /wrongQuestion/findWrongQuestion [get]
|
||||
func (wrongQuestionApi *WrongQuestionApi) FindWrongQuestion(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
rewrongQuestion, err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.GetWrongQuestion(c.Request.Context(), ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(rewrongQuestion, c)
|
||||
}
|
||||
|
||||
// GetWrongQuestionList 分页获取错题记录列表
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 分页获取错题记录列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query learningReq.WrongQuestionSearch true "分页获取错题记录列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /wrongQuestion/getWrongQuestionList [get]
|
||||
func (wrongQuestionApi *WrongQuestionApi) GetWrongQuestionList(c *gin.Context) {
|
||||
var pageInfo learningReq.WrongQuestionSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.GetWrongQuestionInfoList(c.Request.Context(), pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetUserWrongQuestions 获取用户错题列表
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 获取用户错题列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint false "用户ID"
|
||||
// @Param onlyUnmastered query bool false "只获取未掌握的题目"
|
||||
// @Success 200 {object} response.Response{data=[]learning.WrongQuestion,msg=string} "获取成功"
|
||||
// @Router /wrongQuestion/getUserWrongQuestions [get]
|
||||
func (wrongQuestionApi *WrongQuestionApi) GetUserWrongQuestions(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
onlyUnmasteredStr := c.Query("onlyUnmastered")
|
||||
|
||||
var userId uint
|
||||
if userIdStr != "" {
|
||||
userIdUint, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
userId = uint(userIdUint)
|
||||
} else {
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
userId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
onlyUnmastered := onlyUnmasteredStr == "true"
|
||||
|
||||
list, err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.GetUserWrongQuestions(c.Request.Context(), userId, onlyUnmastered)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// MarkAsMastered 标记题目为已掌握
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 标记题目为已掌握
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body learningReq.MarkMasteredRequest true "标记掌握请求"
|
||||
// @Success 200 {object} response.Response{msg=string} "标记成功"
|
||||
// @Router /wrongQuestion/markAsMastered [put]
|
||||
func (wrongQuestionApi *WrongQuestionApi) MarkAsMastered(c *gin.Context) {
|
||||
var req learningReq.MarkMasteredRequest
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
err = service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.MarkAsMastered(c.Request.Context(), req.UserId, req.ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("标记失败!", zap.Error(err))
|
||||
response.FailWithMessage("标记失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("标记成功", c)
|
||||
}
|
||||
|
||||
// GetWrongQuestionStatistics 获取错题统计
|
||||
// @Tags WrongQuestion
|
||||
// @Summary 获取错题统计
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param userId query uint false "用户ID"
|
||||
// @Success 200 {object} response.Response{data=learningReq.WrongQuestionStatistics,msg=string} "获取成功"
|
||||
// @Router /wrongQuestion/getWrongQuestionStatistics [get]
|
||||
func (wrongQuestionApi *WrongQuestionApi) GetWrongQuestionStatistics(c *gin.Context) {
|
||||
userIdStr := c.Query("userId")
|
||||
|
||||
var userId uint
|
||||
if userIdStr != "" {
|
||||
userIdUint, err := strconv.ParseUint(userIdStr, 10, 32)
|
||||
if err != nil {
|
||||
response.FailWithMessage("用户ID格式错误", c)
|
||||
return
|
||||
}
|
||||
userId = uint(userIdUint)
|
||||
} else {
|
||||
// 如果没有提供userId,从JWT中获取当前用户ID
|
||||
userId = uint(utils.GetUserID(c))
|
||||
}
|
||||
|
||||
stats, err := service.ServiceGroupApp.LearningServiceGroup.WrongQuestionService.GetWrongQuestionStatistics(c.Request.Context(), userId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(stats, c)
|
||||
}
|
||||
Reference in New Issue
Block a user