From 9c2489c0c360c8dda36d3cbe1dba79222096b2dd Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 07 八月 2023 10:16:39 +0800
Subject: [PATCH] Merge branch 'master' into fly

---
 api/v1/faq.go |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/api/v1/faq.go b/api/v1/faq.go
new file mode 100644
index 0000000..350dae2
--- /dev/null
+++ b/api/v1/faq.go
@@ -0,0 +1,112 @@
+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, &params)
+	if !ok {
+		return
+	}
+
+	errCode := service.NewFaqService().AddFaq(&params.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, &params)
+	if !ok {
+		return
+	}
+    if params.Id == 0 {
+        ctx.Fail(ecode.ParamsErr)
+    }
+    params.Faq.Id = params.Id
+
+	errCode := service.NewFaqService().UpdateFaq(&params.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,
+	})
+}

--
Gitblit v1.8.0