|
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 RepositoryApi struct{}
|
|
// Add
|
//
|
// @Tags Repository
|
// @Summary 添加退货仓库
|
// @Produce application/json
|
// @Param object body request.AddRepository true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/repository/add [post]
|
func (s *RepositoryApi) Add(c *gin.Context) {
|
var params request.AddRepository
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
repository := new(model.Repository)
|
repository.Name = params.Name
|
|
errCode := repositoryService.AddRepository(repository)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags Repository
|
// @Summary 删除退货仓库
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/repository/delete/{id} [delete]
|
func (s *RepositoryApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := repositoryService.DeleteRepository(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags Repository
|
// @Summary 更新退货仓库
|
// @Produce application/json
|
// @Param object body request.UpdateRepositorys true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/repository/update [put]
|
func (s *RepositoryApi) Update(c *gin.Context) {
|
var params request.UpdateRepositorys
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := repositoryService.UpdateRepository(params.Repositorys)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags Repository
|
// @Summary 获取退货仓库列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.RepositoryResponse}
|
// @Router /api/repository/list [get]
|
func (s *RepositoryApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
repositorys, errCode := repositoryService.GetRepositoryList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.RepositoryResponse{
|
List: repositorys,
|
})
|
}
|