serv_api.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package controller
  2. import (
  3. "Medical_OAuth/app/admin/model"
  4. "Medical_OAuth/app/admin/service"
  5. "Medical_OAuth/app/admin/service/dto"
  6. "github.com/gin-gonic/gin"
  7. "github.com/gin-gonic/gin/binding"
  8. "gogs.baozhida.cn/zoie/OAuth-core/api"
  9. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  10. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  11. )
  12. type ServApi struct {
  13. api.Api
  14. }
  15. // GetPage 获取接口列表
  16. // @Summary 获取接口列表
  17. // @Description 获取接口列表
  18. // @Tags 服务接口
  19. // @Param serviceId query string true "服务ID"
  20. // @Param title query string false "接口名称"
  21. // @Success 200 {object} response.Response{data=response.Page{list=[]model.ServApi}} "{"code": 200, "data": [...]}"
  22. // @Router /api/serv-api [get]
  23. // @Security Bearer
  24. func (e ServApi) GetPage(c *gin.Context) {
  25. s := service.ServApi{}
  26. req := dto.ServApiGetPageReq{}
  27. err := e.MakeContext(c).
  28. MakeOrm().
  29. Bind(&req, binding.Form).
  30. MakeService(&s.Service).
  31. Errors
  32. if err != nil {
  33. e.Logger.Error(err)
  34. e.Error(500, err, err.Error())
  35. return
  36. }
  37. var list = make([]model.ServApi, 0)
  38. var count int64
  39. err = s.GetPage(&req, &list, &count)
  40. if err != nil {
  41. e.Error(500, err, err.Error())
  42. return
  43. }
  44. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  45. }
  46. // Get 通过id获取接口
  47. // @Summary 通过id获取接口
  48. // @Description 通过id获取接口
  49. // @Tags 服务接口
  50. // @Param id path string true "接口id"
  51. // @Success 200 {object} response.Response{data=model.ServApi} "{"code": 200, "data": [...]}"
  52. // @Router /api/serv-api/{id} [get]
  53. // @Security Bearer
  54. func (e ServApi) Get(c *gin.Context) {
  55. req := dto.ServApiGetReq{}
  56. s := service.ServApi{}
  57. err := e.MakeContext(c).
  58. MakeOrm().
  59. Bind(&req, nil).
  60. MakeService(&s.Service).
  61. Errors
  62. if err != nil {
  63. e.Logger.Error(err)
  64. e.Error(500, err, err.Error())
  65. return
  66. }
  67. var object = model.ServApi{}
  68. err = s.Get(&req, &object)
  69. if err != nil {
  70. e.Error(500, err, "查询失败")
  71. return
  72. }
  73. e.OK(object, "查询成功")
  74. }
  75. // Insert 创建接口
  76. // @Summary 创建接口
  77. // @Description 创建接口
  78. // @Tags 服务接口
  79. // @Accept application/json
  80. // @Product application/json
  81. // @Param data body dto.ServApiInsertReq true "data"
  82. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  83. // @Router /api/serv-api [post]
  84. // @Security Bearer
  85. func (e ServApi) Insert(c *gin.Context) {
  86. req := dto.ServApiInsertReq{}
  87. s := service.ServApi{}
  88. err := e.MakeContext(c).
  89. MakeOrm().
  90. Bind(&req, binding.JSON).
  91. MakeService(&s.Service).
  92. Errors
  93. if err != nil {
  94. e.Logger.Error(err)
  95. e.Error(500, err, err.Error())
  96. return
  97. }
  98. // 设置创建人
  99. req.SetCreateBy(user.GetUserId(c))
  100. err = s.Insert(&req)
  101. if err != nil {
  102. e.Error(500, err, err.Error())
  103. return
  104. }
  105. e.OK(req.GetId(), "创建成功")
  106. }
  107. // Update 修改接口
  108. // @Summary 修改接口
  109. // @Description 修改接口
  110. // @Tags 服务接口
  111. // @Accept application/json
  112. // @Product application/json
  113. // @Param id path string true "接口id"
  114. // @Param data body dto.ServApiUpdateReq true "body"
  115. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  116. // @Router /api/serv-api/{id} [put]
  117. // @Security Bearer
  118. func (e ServApi) Update(c *gin.Context) {
  119. s := service.ServApi{}
  120. req := dto.ServApiUpdateReq{}
  121. err := e.MakeContext(c).
  122. MakeOrm().
  123. Bind(&req, binding.JSON, nil).
  124. MakeService(&s.Service).
  125. Errors
  126. if err != nil {
  127. e.Logger.Error(err)
  128. e.Error(500, err, err.Error())
  129. return
  130. }
  131. req.SetUpdateBy(user.GetUserId(c))
  132. err = s.Update(&req)
  133. if err != nil {
  134. e.Error(500, err, err.Error())
  135. return
  136. }
  137. e.OK(req.GetId(), "更新成功")
  138. }
  139. // Delete 删除接口
  140. // @Summary 删除接口
  141. // @Description 删除接口
  142. // @Tags 服务接口
  143. // @Accept application/json
  144. // @Product application/json
  145. // @Param data body dto.ServApiDeleteReq true "body"
  146. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  147. // @Router /api/serv-api [delete]
  148. // @Security Bearer
  149. func (e ServApi) Delete(c *gin.Context) {
  150. s := service.ServApi{}
  151. req := dto.ServApiDeleteReq{}
  152. err := e.MakeContext(c).
  153. MakeOrm().
  154. Bind(&req, binding.JSON).
  155. MakeService(&s.Service).
  156. Errors
  157. if err != nil {
  158. e.Logger.Error(err)
  159. e.Error(500, err, err.Error())
  160. return
  161. }
  162. req.SetUpdateBy(user.GetUserId(c))
  163. err = s.Remove(&req)
  164. if err != nil {
  165. e.Logger.Errorf("RemoveServApi error, %s", err)
  166. e.Error(500, err, "删除失败")
  167. return
  168. }
  169. e.OK(req.GetId(), "删除成功")
  170. }