log_env.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package log
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "log-server/global"
  6. "log-server/model/common/response"
  7. "log-server/model/log"
  8. "log-server/model/log/request"
  9. "log-server/utils"
  10. )
  11. type ApiEnvLog struct {
  12. }
  13. // @Tags logEnv
  14. // @Summary 创建基础环境码
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body request.EnvLogRequest true " coding环境编码, describe环境描述""
  19. // @Success 200 {object} response.Response{msg=string} "创建环境编码"
  20. // @Router /logEnv/create [post]
  21. func (s *ApiEnvLog) CreateEnv(c *gin.Context) {
  22. var api log.EnvLog
  23. _ = c.ShouldBindJSON(&api)
  24. if err := utils.Verify(api, utils.LogCodingVerify); err != nil {
  25. response.FailWithMessage(err.Error(), c)
  26. return
  27. }
  28. if err := ServiceLogEnv.CreateEnv(api); err != nil {
  29. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  30. response.FailWithMessage("创建失败", c)
  31. } else {
  32. response.OkWithMessage("创建成功", c)
  33. }
  34. }
  35. // @Tags logEnv
  36. // @Summary 更新环境编码
  37. // @Security ApiKeyAuth
  38. // @accept application/json
  39. // @Produce application/json
  40. // @Param data body request.EnvLogRequest true "coding环境编码, describe环境描述"
  41. // @Success 200 {object} response.Response{msg=string} "更新环境编码"
  42. // @Router /logEnv/update [post]
  43. func (s *ApiEnvLog) UpdateEnv(c *gin.Context) {
  44. var api request.EnvLogRequest
  45. _ = c.ShouldBindJSON(&api)
  46. if err := utils.Verify(api, utils.LogCodingVerify); err != nil {
  47. response.FailWithMessage(err.Error(), c)
  48. return
  49. }
  50. if api.Id == 0 {
  51. response.FailWithMessage("参数id没有", c)
  52. return
  53. }
  54. if err := ServiceLogEnv.UpdateEnv(api); err != nil {
  55. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  56. response.FailWithMessage("创建失败", c)
  57. } else {
  58. response.OkWithMessage("创建成功", c)
  59. }
  60. }
  61. // @Tags logEnv
  62. // @Summary 根据id获取log env
  63. // @Security ApiKeyAuth
  64. // @accept application/json
  65. // @Produce application/json
  66. // @Param data body request.GetById true "根据id获取log env"
  67. // @Success 200 {object} response.Response{data=response.EnvLogReply} "根据id获取返回log env详情"
  68. // @Router /logEnv/getCodeById [post]
  69. func (s *ApiEnvLog) GetEnvById(c *gin.Context) {
  70. var idInfo request.GetById
  71. _ = c.ShouldBindJSON(&idInfo)
  72. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  73. response.FailWithMessage(err.Error(), c)
  74. return
  75. }
  76. api, err := ServiceLogEnv.GetEnvById(idInfo.ID)
  77. if err != nil {
  78. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  79. response.FailWithMessage("获取失败", c)
  80. } else {
  81. response.OkWithDetailed(api, "获取成功", c)
  82. }
  83. }
  84. // @Tags logEnv
  85. // @Summary 根据id获取log env
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Success 200 {object} response.Response{data=[]response.EnvLogReply} "返回log env列表"
  90. // @Router /logEnv/getEnvList [post]
  91. func (s *ApiEnvLog) GetEnvList(c *gin.Context) {
  92. var paramsInfo request.GetCodeListRequest
  93. _ = c.ShouldBindJSON(&paramsInfo)
  94. api, _, err := ServiceLogEnv.GetEnvList(paramsInfo.OrderKey, paramsInfo.Desc)
  95. if err != nil {
  96. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  97. response.FailWithMessage("获取失败", c)
  98. } else {
  99. response.OkWithDetailed(api, "获取成功", c)
  100. }
  101. }