logistic.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // logisticPage
  12. // @Tags 用户-我的
  13. // @BasePath /clodLogistic/app/api/v1
  14. // @Summary 物流公司列表
  15. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  16. // @Param req body swagger.LogisticPageReqVO true "请求参数"
  17. // @Accept application/json
  18. // @Authorization
  19. // @Router /app/myself/logisticCompany/page [post]
  20. func (api Api) logisticPage(c *gin.Context) {
  21. req := myselfsrv.LogisticPageReqVO{}
  22. if err := c.BindJSON(&req); err != nil {
  23. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  24. return
  25. }
  26. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  27. res, err := srv.LogisticPage(c, req)
  28. if err != nil {
  29. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  30. return
  31. }
  32. core.WriteResponse(c, nil, res)
  33. }
  34. // addLogistic
  35. // @Tags 用户-我的
  36. // @BasePath /clodLogistic/app/api/v1
  37. // @Summary 物流公司添加
  38. // @Success 200 {object} myselfsrv.LogisticIdRespVO "成功响应的结构体"
  39. // @Param req body myselfsrv.AddLogisticReqVO true "请求参数"
  40. // @Accept application/json
  41. // @Authorization
  42. // @Router /app/myself/logisticCompany/add [post]
  43. func (api Api) addLogistic(c *gin.Context) {
  44. req := myselfsrv.AddLogisticReqVO{}
  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. res, err := srv.AddLogistic(c, req)
  55. if err != nil {
  56. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  57. return
  58. }
  59. core.WriteResponse(c, nil, res)
  60. }
  61. // deleteLogistic
  62. // @Tags 用户-我的
  63. // @BasePath /clodLogistic/app/api/v1
  64. // @Summary 物流公司删除
  65. // @Success 200 {object} swagger.BaseResponse "成功响应的结构体"
  66. // @Param req body myselfsrv.DeleteLogisticReqVO true "请求参数"
  67. // @Accept application/json
  68. // @Authorization
  69. // @Router /app/myself/logisticCompany/delete [post]
  70. func (api Api) deleteLogistic(c *gin.Context) {
  71. req := myselfsrv.DeleteLogisticReqVO{}
  72. if err := c.BindJSON(&req); err != nil {
  73. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  74. return
  75. }
  76. if err := req.Validate(); err != nil {
  77. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  78. return
  79. }
  80. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  81. err := srv.DeleteLogistic(c, req)
  82. if err != nil {
  83. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrDeletedFailed, ""))
  84. return
  85. }
  86. core.WriteResponse(c, nil, nil)
  87. }