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 CourierCompanyApi struct{}
|
|
// Add
|
// @Tags 物流公司
|
// @Summary 添加物流公司
|
// @Produce application/json
|
// @Param object body request.AddCourierCompany true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/courierCompany/add [post]
|
func (s *CourierCompanyApi) Add(c *gin.Context) {
|
var params request.AddCourierCompany
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := service.NewCourierCompanyService().AddCourierCompany(¶ms.CourierCompany)
|
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/courierCompany/delete/{id} [delete]
|
func (s *CourierCompanyApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := service.NewCourierCompanyService().DeleteCourierCompany(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
// @Tags 物流公司
|
// @Summary 更新物流公司
|
// @Produce application/json
|
// @Param object body request.UpdateCourierCompany true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/courierCompany/update [put]
|
func (s *CourierCompanyApi) Update(c *gin.Context) {
|
var params request.UpdateCourierCompany
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
if params.Id == 0 {
|
ctx.Fail(ecode.ParamsErr)
|
}
|
params.CourierCompany.Id = params.Id
|
|
errCode := service.NewCourierCompanyService().UpdateCourierCompany(¶ms.CourierCompany)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
// @Tags 物流公司
|
// @Summary 获取物流公司列表
|
// @Produce application/json
|
// @Param object query request.GetCourierCompanyList true "参数"
|
// @Success 200 {object} response.ListResponse{data=[]model.CourierCompany}
|
// @Router /api/courierCompany/list [get]
|
func (s *CourierCompanyApi) List(c *gin.Context) {
|
var params request.GetCourierCompanyList
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
courierCompany, total, errCode := service.NewCourierCompanyService().GetCourierCompanyList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.ListResponse{
|
Data: courierCompany,
|
Count: total,
|
})
|
}
|