event.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package event
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  6. "gitee.com/xuyiping_admin/pkg/valid"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. "gitee.com/xuyiping_admin/pkg/apierr"
  9. "gitee.com/xuyiping_admin/pkg/ginutil"
  10. "github.com/gin-gonic/gin"
  11. )
  12. func EnterEventList(c *gin.Context) {
  13. var req pasturePb.SearchEnterEventRequest
  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.EnterList(c, &req, pagination)
  24. if err != nil {
  25. apierr.ClassifiedAbort(c, err)
  26. return
  27. }
  28. ginutil.JSONResp(c, res)
  29. }
  30. func EnterEventCreate(c *gin.Context) {
  31. var req pasturePb.SearchEnterData
  32. if err := ginutil.BindProto(c, &req); err != nil {
  33. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  34. return
  35. }
  36. if err := valid.ValidateStruct(&req,
  37. valid.Field(&req.CowId, valid.Required),
  38. valid.Field(&req.EarNumber, valid.Required),
  39. valid.Field(&req.BirthAt, valid.Required),
  40. ); err != nil {
  41. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  42. return
  43. }
  44. if err := middleware.BackendOperation(c).OpsService.CreateEnterEvent(c, &req); err != nil {
  45. apierr.ClassifiedAbort(c, err)
  46. return
  47. }
  48. ginutil.JSONResp(c, &operationPb.CommonOK{
  49. Code: http.StatusOK,
  50. Msg: "ok",
  51. Data: &operationPb.Success{Success: true},
  52. })
  53. }