1
This commit is contained in:
@@ -3,8 +3,12 @@ package controller
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Migrate
|
||||
Public // 公共方法-不验证权限
|
||||
AdminUser // 后台用户
|
||||
Question // 题目
|
||||
QuestionQa // 问答题库
|
||||
Public // 公共方法-不验证权限
|
||||
AdminUser // 后台用户
|
||||
Question // 题目
|
||||
QuestionQa // 问答题库
|
||||
QuestionQaItem // 问答题库明细
|
||||
Label // 标签
|
||||
Static // 统计
|
||||
Share // 分享
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
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 Label struct{}
|
||||
|
||||
// GetLabelList 获取标签列表
|
||||
func (r *Label) GetLabelList(c *gin.Context) {
|
||||
labelRequest := requests.LabelRequest{}
|
||||
req := labelRequest.GetLabelList
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
labelDao := dao.LabelDao{}
|
||||
label, err := labelDao.GetLabelListSearch(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetLabelListResponses := dto.GetLabelListDto(label)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(GetLabelListResponses, c)
|
||||
}
|
||||
|
||||
// AddLabel 新增标签
|
||||
func (r *Label) AddLabel(c *gin.Context) {
|
||||
labelRequest := requests.LabelRequest{}
|
||||
req := labelRequest.AddLabel
|
||||
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
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
labelService := service.LabelService{}
|
||||
_, err := labelService.AddLabel(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutLabel 修改标签
|
||||
func (r *Label) PutLabel(c *gin.Context) {
|
||||
labelRequest := requests.LabelRequest{}
|
||||
req := labelRequest.PutLabel
|
||||
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("label_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
labelId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
labelService := service.LabelService{}
|
||||
_, err = labelService.PutLabel(labelId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
@@ -59,6 +59,32 @@ func (r *Question) GetQuestionPage(c *gin.Context) {
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetQuestion 获取题目详情
|
||||
func (r *Question) GetQuestion(c *gin.Context) {
|
||||
id := c.Param("question_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
questionId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionService := service.QuestionService{}
|
||||
getQuestionResponses, err := questionService.GetQuestion(questionId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getQuestionResponses, c)
|
||||
}
|
||||
|
||||
// AddQuestion 新增题目
|
||||
func (r *Question) AddQuestion(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
@@ -191,8 +217,8 @@ func (r *Question) PutQuestionTest(c *gin.Context) {
|
||||
|
||||
// DeleteQuestion 删除题目
|
||||
func (r *Question) DeleteQuestion(c *gin.Context) {
|
||||
couponRequest := requests.QuestionRequest{}
|
||||
req := couponRequest.DeleteQuestion
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.DeleteQuestion
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
@@ -214,3 +240,28 @@ func (r *Question) DeleteQuestion(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetQuestionCount 获取题目数量
|
||||
func (r *Question) GetQuestionCount(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.GetQuestionCount
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
questionDao := dao.QuestionDao{}
|
||||
total, err := questionDao.GetQuestionCountSearch(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(total, c)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (r *QuestionQa) AddQuestionQa(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PutQuestionQa 修改问答题库
|
||||
func (r *Question) PutQuestionQa(c *gin.Context) {
|
||||
func (r *QuestionQa) PutQuestionQa(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQa
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -141,7 +141,7 @@ func (r *Question) PutQuestionQa(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PutQuestionQaPassword 修改问答题库密码
|
||||
func (r *Question) PutQuestionQaPassword(c *gin.Context) {
|
||||
func (r *QuestionQa) PutQuestionQaPassword(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQaPassword
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -180,7 +180,7 @@ func (r *Question) PutQuestionQaPassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PutQuestionQaExpire 修改问答题库有效期
|
||||
func (r *Question) PutQuestionQaExpire(c *gin.Context) {
|
||||
func (r *QuestionQa) PutQuestionQaExpire(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQaExpire
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -217,3 +217,68 @@ func (r *Question) PutQuestionQaExpire(c *gin.Context) {
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionQaRule 修改问答题库规则解释
|
||||
func (r *QuestionQa) PutQuestionQaRule(c *gin.Context) {
|
||||
questionQaRequest := requests.QuestionQaRequest{}
|
||||
req := questionQaRequest.PutQuestionQaRule
|
||||
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.PutQuestionQaRule(qaId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetQuestionQa 获取问答题库详情
|
||||
func (r *QuestionQa) GetQuestionQa(c *gin.Context) {
|
||||
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{}
|
||||
getQuestionQaResponses, err := questionQaService.GetQuestionQa(qaId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getQuestionQaResponses, c)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
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 QuestionQaItem struct{}
|
||||
|
||||
// GetQuestionQaItemPage 获取问答题库明细列表-分页
|
||||
func (r *QuestionQaItem) GetQuestionQaItemPage(c *gin.Context) {
|
||||
questionQaItemRequest := requests.QuestionQaItemRequest{}
|
||||
req := questionQaItemRequest.GetQuestionQaItemPage
|
||||
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
|
||||
}
|
||||
|
||||
questionQaItemDao := dao.QuestionQaItemDao{}
|
||||
questionQaItem, total, err := questionQaItemDao.GetQuestionQaItemPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
questionQaItemPageResponses := dto.GetQuestionQaItemListDto(questionQaItem)
|
||||
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"] = questionQaItemPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// DeleteQuestionQaItem 删除问答题库明细
|
||||
func (r *QuestionQaItem) DeleteQuestionQaItem(c *gin.Context) {
|
||||
questionQaItemRequest := requests.QuestionQaItemRequest{}
|
||||
req := questionQaItemRequest.DeleteQuestionQaItem
|
||||
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
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaItemService := service.QuestionQaItemService{}
|
||||
_, err := questionQaItemService.DeleteQuestionQaItem(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutQuestionQaItemMust 修改必选
|
||||
func (r *QuestionQaItem) PutQuestionQaItemMust(c *gin.Context) {
|
||||
questionQaItemRequest := requests.QuestionQaItemRequest{}
|
||||
req := questionQaItemRequest.PutQuestionQaItemMust
|
||||
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("item_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
itemId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
questionQaItemService := service.QuestionQaItemService{}
|
||||
_, err = questionQaItemService.PutQuestionQaItemMust(itemId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/requests"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/api/service"
|
||||
"knowledge/global"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
type Share struct{}
|
||||
|
||||
// GetShare 获取分享数据
|
||||
func (r *Share) GetShare(c *gin.Context) {
|
||||
shareRequest := requests.ShareRequest{}
|
||||
req := shareRequest.GetShare
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
shareService := service.ShareService{}
|
||||
getShareResponses, err := shareService.GetShare(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getShareResponses, c)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/api/responses"
|
||||
"knowledge/api/service"
|
||||
)
|
||||
|
||||
type Static struct{}
|
||||
|
||||
// GetStatic 获取统计数据
|
||||
func (r *Static) GetStatic(c *gin.Context) {
|
||||
// 业务处理
|
||||
staticService := service.StaticService{}
|
||||
getStaticResponses, err := staticService.GetStatic()
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getStaticResponses, c)
|
||||
}
|
||||
Reference in New Issue
Block a user