package v1
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type ClientOriginApi struct{}
|
|
// Add
|
//
|
// @Tags ClientOrigin
|
// @Summary 添加客户来源
|
// @Produce application/json
|
// @Param object body request.AddClientOrigin true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/clientOrigin/add [post]
|
func (co *ClientOriginApi) Add(c *gin.Context) {
|
var params request.AddClientOrigin
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
clientOrigin := new(model.ClientOrigin)
|
clientOrigin.Name = params.Name
|
|
errCode := clientOriginService.AddClientOrigin(clientOrigin)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags ClientOrigin
|
// @Summary 删除客户来源
|
// @Produce application/json
|
// @Param id path int true "客户来源ID"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/clientOrigin/delete/{id} [delete]
|
func (co *ClientOriginApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := clientOriginService.DeleteClientOrigin(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags ClientOrigin
|
// @Summary 更新客户来源
|
// @Produce application/json
|
// @Param object body request.UpdateClientOriginList true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/clientOrigin/update [put]
|
func (co *ClientOriginApi) Update(c *gin.Context) {
|
var params request.UpdateClientOriginList
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := clientOriginService.UpdateClientOrigin(params.ClientOrigins)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags ClientOrigin
|
// @Summary 获取客户来源列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.ClientOriginResponse}
|
// @Router /api/clientOrigin/list [get]
|
func (co *ClientOriginApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
clientOrigins, errCode := clientOriginService.GetClientOriginList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.ClientOriginResponse{
|
List: clientOrigins,
|
})
|
}
|