cow.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package cow
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "gitee.com/xuyiping_admin/pkg/valid"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. "gitee.com/xuyiping_admin/pkg/apierr"
  8. "gitee.com/xuyiping_admin/pkg/ginutil"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func List(c *gin.Context) {
  12. var req pasturePb.SearchEventRequest
  13. if err := ginutil.BindProto(c, &req); err != nil {
  14. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  15. return
  16. }
  17. pagination := &pasturePb.PaginationModel{
  18. Page: int32(c.GetInt(middleware.Page)),
  19. PageSize: int32(c.GetInt(middleware.PageSize)),
  20. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  21. }
  22. res, err := middleware.Dependency(c).StoreEventHub.OpsService.List(c, &req, pagination)
  23. if err != nil {
  24. apierr.ClassifiedAbort(c, err)
  25. return
  26. }
  27. ginutil.JSONResp(c, res)
  28. }
  29. func EventList(c *gin.Context) {
  30. var req pasturePb.SearchCowEventListRequest
  31. if err := ginutil.BindProto(c, &req); err != nil {
  32. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  33. return
  34. }
  35. if err := valid.ValidateStruct(&req,
  36. valid.Field(&req.CowId, valid.Required),
  37. ); err != nil {
  38. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  39. return
  40. }
  41. pagination := &pasturePb.PaginationModel{
  42. Page: int32(c.GetInt(middleware.Page)),
  43. PageSize: int32(c.GetInt(middleware.PageSize)),
  44. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  45. }
  46. res, err := middleware.Dependency(c).StoreEventHub.OpsService.EventList(c, &req, pagination)
  47. if err != nil {
  48. apierr.ClassifiedAbort(c, err)
  49. return
  50. }
  51. ginutil.JSONResp(c, res)
  52. }