barn.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package pasture
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. "gitee.com/xuyiping_admin/pkg/apierr"
  8. "gitee.com/xuyiping_admin/pkg/ginutil"
  9. "gitee.com/xuyiping_admin/pkg/valid"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func SearchBarnList(c *gin.Context) {
  13. var req pasturePb.SearchNameRequest
  14. if err := ginutil.BindProto(c, &req); err != nil {
  15. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  16. return
  17. }
  18. pagination := &pasturePb.PaginationModel{
  19. Page: int32(c.GetInt(middleware.Page)),
  20. PageSize: int32(c.GetInt(middleware.PageSize)),
  21. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  22. }
  23. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchBarnList(c, &req, pagination)
  24. if err != nil {
  25. apierr.ClassifiedAbort(c, err)
  26. return
  27. }
  28. ginutil.JSONResp(c, res)
  29. }
  30. // CreatedOrUpdateBarn 添加或者更新栏舍
  31. func CreatedOrUpdateBarn(c *gin.Context) {
  32. var req pasturePb.SearchBarnList
  33. if err := ginutil.BindProto(c, &req); err != nil {
  34. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  35. return
  36. }
  37. if err := valid.ValidateStruct(&req,
  38. valid.Field(&req.Name, valid.Required),
  39. valid.Field(&req.Lengths, valid.Required, valid.Min(1)),
  40. valid.Field(&req.Widths, valid.Required, valid.Min(1)),
  41. valid.Field(&req.DoctrinalCapacity, valid.Required, valid.Min(1)),
  42. ); err != nil {
  43. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  44. return
  45. }
  46. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBarn(c, &req); err != nil {
  47. apierr.ClassifiedAbort(c, err)
  48. return
  49. }
  50. ginutil.JSONResp(c, &operationPb.CommonOK{
  51. Code: http.StatusOK,
  52. Msg: "ok",
  53. Data: &operationPb.Success{Success: true},
  54. })
  55. }
  56. func SearchBarnTypeList(c *gin.Context) {
  57. var req pasturePb.SearchNameRequest
  58. if err := ginutil.BindProto(c, &req); err != nil {
  59. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  60. return
  61. }
  62. pagination := &pasturePb.PaginationModel{
  63. Page: int32(c.GetInt(middleware.Page)),
  64. PageSize: int32(c.GetInt(middleware.PageSize)),
  65. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  66. }
  67. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchBarnTypeList(c, &req, pagination)
  68. if err != nil {
  69. apierr.ClassifiedAbort(c, err)
  70. return
  71. }
  72. ginutil.JSONResp(c, res)
  73. }
  74. // CreatedOrUpdateBarnType 添加或者更新栏舍类型
  75. func CreatedOrUpdateBarnType(c *gin.Context) {
  76. var req pasturePb.SearchBaseConfigList
  77. if err := ginutil.BindProto(c, &req); err != nil {
  78. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  79. return
  80. }
  81. if err := valid.ValidateStruct(&req,
  82. valid.Field(&req.Name, valid.Required),
  83. ); err != nil {
  84. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  85. return
  86. }
  87. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateBarnType(c, &req); err != nil {
  88. apierr.ClassifiedAbort(c, err)
  89. return
  90. }
  91. ginutil.JSONResp(c, &operationPb.CommonOK{
  92. Code: http.StatusOK,
  93. Msg: "ok",
  94. Data: &operationPb.Success{Success: true},
  95. })
  96. }