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