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(), "删除成功") }