address.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // addressPage
  12. // @Tags 用户-我的
  13. // @BasePath /clodLogistic/app/api/v1
  14. // @Summary 寄件/收件人列表
  15. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  16. // @Param req body swagger.AddressPageReqVO true "请求参数"
  17. // @Accept application/json
  18. // @Authorization
  19. // @Router /app/myself/address/page [post]
  20. func (api Api) addressPage(c *gin.Context) {
  21. req := myselfsrv.AddressPageReqVO{}
  22. if err := c.BindJSON(&req); err != nil {
  23. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  24. return
  25. }
  26. if err := req.Validate(); err != nil {
  27. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  28. return
  29. }
  30. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  31. res, err := srv.AddressPage(c, req)
  32. if err != nil {
  33. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  34. return
  35. }
  36. core.WriteResponse(c, nil, res)
  37. }
  38. // addAddress
  39. // @Tags 用户-我的
  40. // @BasePath /clodLogistic/app/api/v1
  41. // @Summary 添加寄件/收件人
  42. // @Success 200 {object} myselfsrv.AddressIdRespVO "成功响应的结构体"
  43. // @Param req body myselfsrv.AddAddressReqVO true "请求参数"
  44. // @Accept application/json
  45. // @Authorization
  46. // @Router /app/myself/address/add [post]
  47. func (api Api) addAddress(c *gin.Context) {
  48. req := myselfsrv.AddAddressReqVO{}
  49. if err := c.BindJSON(&req); err != nil {
  50. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  51. return
  52. }
  53. if err := req.Validate(); err != nil {
  54. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  55. return
  56. }
  57. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  58. res, err := srv.AddAddress(c, req)
  59. if err != nil {
  60. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  61. return
  62. }
  63. core.WriteResponse(c, nil, res)
  64. }
  65. // updateAddress
  66. // @Tags 用户-我的
  67. // @BasePath /clodLogistic/app/api/v1
  68. // @Summary 修改寄件/收件人
  69. // @Success 200 {object} myselfsrv.AddressIdRespVO "成功响应的结构体"
  70. // @Param req body myselfsrv.UpdateAddressReqVO true "请求参数"
  71. // @Accept application/json
  72. // @Authorization
  73. // @Router /app/myself/address/update [post]
  74. func (api Api) updateAddress(c *gin.Context) {
  75. req := myselfsrv.UpdateAddressReqVO{}
  76. if err := c.BindJSON(&req); err != nil {
  77. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  78. return
  79. }
  80. if err := req.Validate(); err != nil {
  81. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  82. return
  83. }
  84. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  85. res, err := srv.UpdateAddress(c, req)
  86. if err != nil {
  87. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  88. return
  89. }
  90. core.WriteResponse(c, nil, res)
  91. }
  92. // deleteAddress
  93. // @Tags 用户-我的
  94. // @Summary 删除寄件/收件人
  95. // @Success 200 {object} swagger.BaseResponse "成功响应的结构体"
  96. // @Param req body myselfsrv.DeleteAddressReqVO true "请求参数"
  97. // @Accept application/json
  98. // @Router /app/myself/address/delete [post]
  99. func (api Api) deleteAddress(c *gin.Context) {
  100. req := myselfsrv.DeleteAddressReqVO{}
  101. if err := c.BindJSON(&req); err != nil {
  102. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  103. return
  104. }
  105. if err := req.Validate(); err != nil {
  106. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  107. return
  108. }
  109. srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  110. err := srv.DeleteAddress(c, req)
  111. if err != nil {
  112. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrDeletedFailed, ""))
  113. return
  114. }
  115. core.WriteResponse(c, nil, nil)
  116. }