pasture.go 1005 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package pasture
  2. import (
  3. "kpt-tmr-group/http/middleware"
  4. "kpt-tmr-group/pkg/apierr"
  5. "kpt-tmr-group/pkg/apiok"
  6. operationPb "kpt-tmr-group/proto/go/backend/operation"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func AddSystemPasture(c *gin.Context) {
  11. var req operationPb.AddPastureRequest
  12. if err := c.BindJSON(&req); err != nil {
  13. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  14. return
  15. }
  16. if err := middleware.BackendOperation(c).OpsService.CreatePasture(c, &req); err != nil {
  17. apierr.ClassifiedAbort(c, err)
  18. return
  19. }
  20. c.JSON(http.StatusOK, apiok.CommonResponse(apiok.NewApiOk(true)))
  21. }
  22. func SearchPastureList(c *gin.Context) {
  23. req := &operationPb.SearchPastureRequest{}
  24. if err := c.BindJSON(req); err != nil {
  25. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  26. return
  27. }
  28. res, err := middleware.BackendOperation(c).OpsService.SearchPastureList(c, req)
  29. if err != nil {
  30. apierr.ClassifiedAbort(c, err)
  31. return
  32. }
  33. c.JSON(http.StatusOK, apiok.CommonResponse(res.ToPB()))
  34. }