新增了 问答题库管理
This commit is contained in:
@@ -3,7 +3,8 @@ package controller
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Migrate
|
||||
Public // 公共方法-不验证权限
|
||||
AdminUser // 后台用户
|
||||
Question // 题目
|
||||
Public // 公共方法-不验证权限
|
||||
AdminUser // 后台用户
|
||||
Question // 题目
|
||||
QuestionQa // 问答题库
|
||||
}
|
||||
|
||||
@@ -188,3 +188,29 @@ func (r *Question) PutQuestionTest(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// DeleteQuestion 删除题目
|
||||
func (r *Question) DeleteQuestion(c *gin.Context) {
|
||||
couponRequest := requests.QuestionRequest{}
|
||||
req := couponRequest.DeleteQuestion
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionService := service.QuestionService{}
|
||||
_, err := questionService.DeleteQuestion(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/dao"
|
||||
"knowledge/api/dto"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/api/service"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type QuestionQa struct{}
|
||||
|
||||
// GetQuestionQaPage 获取问答题库列表-分页
|
||||
func (r *QuestionQa) GetQuestionQaPage(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.GetQuestionQaPage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
questionQaDao := dao.QuestionQaDao{}
|
||||
questionQa, total, err := questionQaDao.GetQuestionQaPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetQuestionQaPageResponses := dto.GetQuestionQaListDto(questionQa)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetQuestionQaPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// AddQuestionQa 新增问答题库
|
||||
func (r *QuestionQa) AddQuestionQa(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.AddQuestionQa
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
for _, item := range req.Item {
|
||||
if err := global.Validate.Struct(item); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaService := service.QuestionQaService{}
|
||||
_, err := questionQaService.AddQuestionQa(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionQa 修改问答题库
|
||||
func (r *Question) PutQuestionQa(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQa
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
for _, item := range req.Item {
|
||||
if err := global.Validate.Struct(item); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
id := c.Param("qa_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
qaId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaService := service.QuestionQaService{}
|
||||
_, err = questionQaService.PutQuestionQa(qaId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionQaPassword 修改问答题库密码
|
||||
func (r *Question) PutQuestionQaPassword(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQaPassword
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("qa_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
qaId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaService := service.QuestionQaService{}
|
||||
_, err = questionQaService.PutQuestionQaPassword(qaId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionQaExpire 修改问答题库有效期
|
||||
func (r *Question) PutQuestionQaExpire(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQaExpire
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("qa_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
qaId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaService := service.QuestionQaService{}
|
||||
_, err = questionQaService.PutQuestionQaExpire(qaId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
Reference in New Issue
Block a user