package myself import ( "Cold_Logistic/internal/pkg/common/codex" "Cold_Logistic/internal/pkg/common/global" "Cold_Logistic/internal/server/application/myselfsrv" "Cold_Logistic/internal/server/infra/dao" "github.com/gin-gonic/gin" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors" ) // addressPage // @Tags 用户-我的 // @BasePath /clodLogistic/app/api/v1 // @Summary 寄件/收件人列表 // @Success 200 {object} swagger.PageListResponse "成功响应的结构体" // @Param req body swagger.AddressPageReqVO true "请求参数" // @Accept application/json // @Authorization // @Router /app/myself/address/page [post] func (api Api) addressPage(c *gin.Context) { req := myselfsrv.AddressPageReqVO{} if err := c.BindJSON(&req); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, "")) return } if err := req.Validate(); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:")) return } srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)) res, err := srv.AddressPage(c, req) if err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, "")) return } core.WriteResponse(c, nil, res) } // addAddress // @Tags 用户-我的 // @BasePath /clodLogistic/app/api/v1 // @Summary 添加寄件/收件人 // @Success 200 {object} myselfsrv.AddressIdRespVO "成功响应的结构体" // @Param req body myselfsrv.AddAddressReqVO true "请求参数" // @Accept application/json // @Authorization // @Router /app/myself/address/add [post] func (api Api) addAddress(c *gin.Context) { req := myselfsrv.AddAddressReqVO{} if err := c.BindJSON(&req); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, "")) return } if err := req.Validate(); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:")) return } srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)) res, err := srv.AddAddress(c, req) if err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, "")) return } core.WriteResponse(c, nil, res) } // updateAddress // @Tags 用户-我的 // @BasePath /clodLogistic/app/api/v1 // @Summary 修改寄件/收件人 // @Success 200 {object} myselfsrv.AddressIdRespVO "成功响应的结构体" // @Param req body myselfsrv.UpdateAddressReqVO true "请求参数" // @Accept application/json // @Authorization // @Router /app/myself/address/update [post] func (api Api) updateAddress(c *gin.Context) { req := myselfsrv.UpdateAddressReqVO{} if err := c.BindJSON(&req); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, "")) return } if err := req.Validate(); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:")) return } srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)) res, err := srv.UpdateAddress(c, req) if err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, "")) return } core.WriteResponse(c, nil, res) } // deleteAddress // @Tags 用户-我的 // @Summary 删除寄件/收件人 // @Success 200 {object} swagger.BaseResponse "成功响应的结构体" // @Param req body myselfsrv.DeleteAddressReqVO true "请求参数" // @Accept application/json // @Router /app/myself/address/delete [post] func (api Api) deleteAddress(c *gin.Context) { req := myselfsrv.DeleteAddressReqVO{} if err := c.BindJSON(&req); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, "")) return } if err := req.Validate(); err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:")) return } srv := myselfsrv.NewMyselfService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)) err := srv.DeleteAddress(c, req) if err != nil { core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrDeletedFailed, "")) return } core.WriteResponse(c, nil, nil) }