telco_server/app/admin/apis/bus_apis/a_cooperative_manage.go

191 lines
4.7 KiB
Go

package bus_apis
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/bus_models"
"go-admin/app/admin/service/bus_service"
"go-admin/tools/app"
"net/http"
)
type CooperativeApi struct {
api.Api
}
// CooperativeList 查询合作商列表
// @Summary 查询合作商列表
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.CooperativeListReq true "查询合作商列表模型"
// @Success 200 {object} bus_models.CooperativeListResp
// @Router /api/v1/cooperative/list [post]
func (e CooperativeApi) CooperativeList(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.CooperativeListReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层的 GetCooperativeList 函数获取数据
resp, err := s.GetCooperativeList(c.Request.Context(), req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
// 返回查询结果
app.OK(c, resp, "查询成功")
return
}
// CreateCooperative 新建合作商
// @Summary 新建合作商
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.CreateCooperativeReq true "新建合作商模型"
// @Success 200 {object} bus_models.CreateCooperativeResp
// @Router /api/v1/cooperative/create [post]
func (e CooperativeApi) CreateCooperative(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.CreateCooperativeReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层的 CreateCooperative 函数来处理逻辑
resp, err := s.CreateCooperative(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
// 返回创建结果
app.OK(c, resp, "新增成功")
return
}
// EditCooperative 编辑合作商
// @Summary 编辑合作商
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.EditCooperativeReq true "编辑合作商模型"
// @Success 200 {object} app.Response
// @Router /api/v1/cooperative/edit [post]
func (e CooperativeApi) EditCooperative(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.EditCooperativeReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层的 EditCooperative 函数来处理逻辑
err = s.EditCooperative(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
// 返回创建结果
app.OK(c, nil, "编辑成功")
return
}
// DeleteCooperative 删除合作商
// @Summary 删除合作商
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.DeleteCooperativeReq true "删除合作商模型"
// @Success 200 {object} app.Response
// @Router /api/v1/cooperative/delete [post]
func (e CooperativeApi) DeleteCooperative(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.DeleteCooperativeReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层的 DeleteCooperative 函数来处理逻辑
err = s.DeleteCooperative(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
// 返回创建结果
app.OK(c, nil, "删除成功")
return
}
// CooperativeDetail 查询合作商详情
// @Summary 查询合作商详情
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.CooperativeDetailReq true "查询合作商详情请求参数"
// @Success 200 {object} bus_models.CooperativeDetailResp
// @Router /api/v1/cooperative/detail [post]
func (e CooperativeApi) CooperativeDetail(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.CooperativeDetailReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层的 GetCooperativeDetail 函数获取数据
resp, err := s.GetCooperativeDetail(c.Request.Context(), req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
// 返回查询结果
app.OK(c, resp, "查询成功")
return
}