123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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)
- }
|