logistic.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package myself
  2. import (
  3. "Cold_Logistic/internal/pkg/common/codex"
  4. "Cold_Logistic/internal/pkg/common/global"
  5. "Cold_Logistic/internal/server/application/myselfsrv"
  6. "Cold_Logistic/internal/server/infra/dao"
  7. "github.com/gin-gonic/gin"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  10. )
  11. func (api Api) logisticPage(c *gin.Context) {
  12. req := myselfsrv.LogisticPageReqVO{}
  13. if err := c.BindJSON(&req); err != nil {
  14. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  15. return
  16. }
  17. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  18. res, err := srv.LogisticPage(c, req)
  19. if err != nil {
  20. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  21. return
  22. }
  23. core.WriteResponse(c, nil, res)
  24. }
  25. func (api Api) addLogistic(c *gin.Context) {
  26. req := myselfsrv.AddLogisticReqVO{}
  27. if err := c.BindJSON(&req); err != nil {
  28. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  29. return
  30. }
  31. if err := req.Validate(); err != nil {
  32. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  33. return
  34. }
  35. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  36. res, err := srv.AddLogistic(c, req)
  37. if err != nil {
  38. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  39. return
  40. }
  41. core.WriteResponse(c, nil, res)
  42. }
  43. func (api Api) deleteLogistic(c *gin.Context) {
  44. req := myselfsrv.DeleteLogisticReqVO{}
  45. if err := c.BindJSON(&req); err != nil {
  46. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  47. return
  48. }
  49. if err := req.Validate(); err != nil {
  50. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  51. return
  52. }
  53. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  54. err := srv.DeleteLogistic(c, req)
  55. if err != nil {
  56. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrDeletedFailed, ""))
  57. return
  58. }
  59. core.WriteResponse(c, nil, nil)
  60. }