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 IndustryApi struct{}
|
|
// Add
|
//
|
// @Tags Industry
|
// @Summary 添加行业
|
// @Produce application/json
|
// @Param object body request.AddIndustry true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/industry/add [post]
|
func (ia *IndustryApi) Add(c *gin.Context) {
|
var params request.AddIndustry
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
industry := new(model.Industry)
|
industry.Name = params.Name
|
|
errCode := industryService.AddIndustry(industry)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags Industry
|
// @Summary 删除行业
|
// @Produce application/json
|
// @Param id path int true "行业ID"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/industry/delete/{id} [delete]
|
func (ia *IndustryApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := industryService.DeleteIndustry(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags Industry
|
// @Summary 更新行业
|
// @Produce application/json
|
// @Param object body request.UpdateIndustries true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/industry/update [put]
|
func (ia *IndustryApi) Update(c *gin.Context) {
|
var params request.UpdateIndustries
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := industryService.UpdateIndustry(params.Industries)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags Industry
|
// @Summary 行业列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.IndustryResponse}
|
// @Router /api/industry/list [get]
|
func (ia *IndustryApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
industries, errCode := industryService.GetIndustryList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.IndustryResponse{List: industries})
|
|
}
|