123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package controller
- import (
- "Medical_OAuth/app/admin/model"
- "Medical_OAuth/app/admin/service"
- "Medical_OAuth/app/admin/service/dto"
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "gogs.baozhida.cn/zoie/OAuth-core/api"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
- _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
- )
- type ServApi struct {
- api.Api
- }
- // GetPage 获取接口列表
- // @Summary 获取接口列表
- // @Description 获取接口列表
- // @Tags 服务接口
- // @Param serviceId query string true "服务ID"
- // @Param title query string false "接口名称"
- // @Success 200 {object} response.Response{data=response.Page{list=[]model.ServApi}} "{"code": 200, "data": [...]}"
- // @Router /api/serv-api [get]
- // @Security Bearer
- func (e ServApi) GetPage(c *gin.Context) {
- s := service.ServApi{}
- req := dto.ServApiGetPageReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.Form).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var list = make([]model.ServApi, 0)
- var count int64
- err = s.GetPage(&req, &list, &count)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // Get 通过id获取接口
- // @Summary 通过id获取接口
- // @Description 通过id获取接口
- // @Tags 服务接口
- // @Param id path string true "接口id"
- // @Success 200 {object} response.Response{data=model.ServApi} "{"code": 200, "data": [...]}"
- // @Router /api/serv-api/{id} [get]
- // @Security Bearer
- func (e ServApi) Get(c *gin.Context) {
- req := dto.ServApiGetReq{}
- s := service.ServApi{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object = model.ServApi{}
- err = s.Get(&req, &object)
- if err != nil {
- e.Error(500, err, "查询失败")
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 创建接口
- // @Summary 创建接口
- // @Description 创建接口
- // @Tags 服务接口
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.ServApiInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/serv-api [post]
- // @Security Bearer
- func (e ServApi) Insert(c *gin.Context) {
- req := dto.ServApiInsertReq{}
- s := service.ServApi{}
- 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
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "创建成功")
- }
- // Update 修改接口
- // @Summary 修改接口
- // @Description 修改接口
- // @Tags 服务接口
- // @Accept application/json
- // @Product application/json
- // @Param id path string true "接口id"
- // @Param data body dto.ServApiUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/serv-api/{id} [put]
- // @Security Bearer
- func (e ServApi) Update(c *gin.Context) {
- s := service.ServApi{}
- req := dto.ServApiUpdateReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req, binding.JSON, nil).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Update(&req)
- if err != nil {
- e.Error(500, err, err.Error())
- return
- }
- e.OK(req.GetId(), "更新成功")
- }
- // Delete 删除接口
- // @Summary 删除接口
- // @Description 删除接口
- // @Tags 服务接口
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.ServApiDeleteReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
- // @Router /api/serv-api [delete]
- // @Security Bearer
- func (e ServApi) Delete(c *gin.Context) {
- s := service.ServApi{}
- req := dto.ServApiDeleteReq{}
- 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
- }
- req.SetUpdateBy(user.GetUserId(c))
- err = s.Remove(&req)
- if err != nil {
- e.Logger.Errorf("RemoveServApi error, %s", err)
- e.Error(500, err, "删除失败")
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
|