package v1
|
|
import (
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"aps_crm/service"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type FaqApi struct{}
|
|
// Add
|
// @Tags 常见问题管理
|
// @Summary 添加常见问题
|
// @Produce application/json
|
// @Param object body request.AddFaq true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/faq/add [post]
|
func (s *FaqApi) Add(c *gin.Context) {
|
var params request.AddFaq
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := service.NewFaqService().AddFaq(¶ms.Faq)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
// @Tags 常见问题管理
|
// @Summary 删除常见问题
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/faq/delete/{id} [delete]
|
func (s *FaqApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := service.NewFaqService().DeleteFaq(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
// @Tags 常见问题管理
|
// @Summary 更新常见问题
|
// @Produce application/json
|
// @Param object body request.UpdateFaq true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/faq/update [put]
|
func (s *FaqApi) Update(c *gin.Context) {
|
var params request.UpdateFaq
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
if params.Id == 0 {
|
ctx.Fail(ecode.ParamsErr)
|
}
|
params.Faq.Id = params.Id
|
|
errCode := service.NewFaqService().UpdateFaq(¶ms.Faq)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
// @Tags 常见问题管理
|
// @Summary 获取常见问题列表
|
// @Produce application/json
|
// @Param object body request.GetFaqList true "参数"
|
// @Success 200 {object} response.ListResponse{data=[]model.Faq}
|
// @Router /api/faq/list [get]
|
func (s *FaqApi) List(c *gin.Context) {
|
var params request.GetFaqList
|
ctx, ok := contextx.NewContext(c, params)
|
if !ok {
|
return
|
}
|
|
faq, total, errCode := service.NewFaqService().GetFaqList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.ListResponse{
|
Data: faq,
|
Count: total,
|
})
|
}
|