From 6b2213d5809544e4daf340b1c5aeffa7f16c3e87 Mon Sep 17 00:00:00 2001 From: fansili Date: Fri, 8 May 2020 10:28:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20rest=20api(=E7=94=A8=E6=88=B7=E5=9C=B0=E5=9D=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/convert/user/UserAddressConvert.java | 10 +-- .../user/biz/dao/user/UserAddressMapper.java | 18 ++-- ...AddressDO.java => UsersUserAddressDO.java} | 2 +- .../biz/service/user/UserAddressService.java | 38 ++++++++- .../service/user/UserAddressServiceImpl.java | 85 ++++++++----------- user/user-rest/pom.xml | 22 ++--- .../user/UsersUserAddressController.java | 80 +++++++++++++++++ .../user/rest/convert/UserAddressConvert.java | 37 ++++++++ .../rest/request/UserAddressAddRequest.java | 41 +++++++++ .../request/UserAddressUpdateRequest.java | 45 ++++++++++ .../mall/user/rest/request/package-info.java | 5 ++ .../rest/response/UserAddressResponse.java | 41 +++++++++ .../mall/user/rest/response/package-info.java | 5 ++ .../mall/user/rpc/api/UserAddressRPC.java | 2 +- .../user/rpc/rpc/user/UserAddressRPCImpl.java | 6 +- 15 files changed, 358 insertions(+), 79 deletions(-) rename user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/{UserAddressDO.java => UsersUserAddressDO.java} (93%) create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/controller/user/UsersUserAddressController.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/convert/UserAddressConvert.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressAddRequest.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressUpdateRequest.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/package-info.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/UserAddressResponse.java create mode 100644 user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/package-info.java diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java index 21231e225..abbf44eea 100644 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java +++ b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.user.biz.convert.user; import cn.iocoder.mall.user.biz.bo.user.UserAddressBO; -import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.user.biz.dataobject.user.UsersUserAddressDO; import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO; import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO; import org.mapstruct.Mapper; @@ -22,14 +22,14 @@ public interface UserAddressConvert { UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class); @Mappings({}) - UserAddressDO convert(UserAddressAddDTO userAddressAddDTO); + UsersUserAddressDO convert(UserAddressAddDTO userAddressAddDTO); @Mappings({}) - UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO); + UsersUserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO); @Mappings({}) - UserAddressBO convert(UserAddressDO userAddressDO); + UserAddressBO convert(UsersUserAddressDO userAddressDO); @Mappings({}) - List convertUserAddressBOList(List userAddressDOList); + List convertUserAddressBOList(List userAddressDOList); } diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java index bf33a37b5..e9aed689b 100644 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java +++ b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.user.biz.dao.user; -import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.user.biz.dataobject.user.UsersUserAddressDO; import cn.iocoder.mall.user.biz.enums.user.UserAddressHasDefaultEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -16,18 +16,18 @@ import java.util.List; */ @Repository // TODO done FROM 芋艿 to 小范:替换成 Mybatis Plus -public interface UserAddressMapper extends BaseMapper { +public interface UserAddressMapper extends BaseMapper { - default List selectByUserId(Integer userId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(UserAddressDO::getUserId, userId); + default List selectByUserId(Integer userId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UsersUserAddressDO::getUserId, userId); return selectList(wrapper); } - default UserAddressDO selectHasDefault(Integer userId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(UserAddressDO::getUserId, userId); - wrapper.eq(UserAddressDO::getHasDefault, UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + default UsersUserAddressDO selectHasDefault(Integer userId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UsersUserAddressDO::getUserId, userId); + wrapper.eq(UsersUserAddressDO::getHasDefault, UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); return selectOne(wrapper); } } diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UserAddressDO.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java similarity index 93% rename from user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UserAddressDO.java rename to user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java index b6112b911..3b49d0e9a 100644 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UserAddressDO.java +++ b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java @@ -12,7 +12,7 @@ import lombok.experimental.Accessors; */ @Data @Accessors(chain = true) -public class UserAddressDO extends DeletableDO { +public class UsersUserAddressDO extends DeletableDO { /** * 编号 diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java index 659ea1f3d..294357237 100644 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java +++ b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java @@ -14,15 +14,49 @@ import java.util.List; */ public interface UserAddressService { + /** + * 添加地址 + * + * @param userAddressAddDTO + */ void addAddress(UserAddressAddDTO userAddressAddDTO); + /** + * 更新 - 根据id 更新 + * + * @param userAddressAddDTO + */ void updateAddress(UserAddressUpdateDTO userAddressAddDTO); + /** + * 删除 - 更新id 删除 + * + * @param userId + * @param addressId + */ void removeAddress(Integer userId, Integer addressId); - List addressList(Integer userId); + /** + * 获取 - 用户所有地址 + * + * @param userId + * @return + */ + List listAddress(Integer userId); - UserAddressBO getAddress(Integer userId, Integer id); + /** + * 获取 - 根据id 获取地址 + * + * @param id + * @return + */ + UserAddressBO getAddress(Integer id); + /** + * 获取 - 获取用户 default 地址 + * + * @param userId + * @return + */ UserAddressBO getDefaultAddress(Integer userId); } diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java index 111eecbbe..6c54db9d4 100644 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java +++ b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java @@ -6,7 +6,7 @@ import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; import cn.iocoder.mall.user.biz.bo.user.UserAddressBO; import cn.iocoder.mall.user.biz.convert.user.UserAddressConvert; import cn.iocoder.mall.user.biz.dao.user.UserAddressMapper; -import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.user.biz.dataobject.user.UsersUserAddressDO; import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO; import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO; import cn.iocoder.mall.user.biz.enums.user.UserAddressHasDefaultEnum; @@ -32,112 +32,101 @@ public class UserAddressServiceImpl implements UserAddressService { @Override @Transactional public void addAddress(UserAddressAddDTO userAddressAddDTO) { - UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + + // 转换do,设置默认数据 + UsersUserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); userAddressDO.setCreateTime(new Date()); userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); // 检查是否设置为默认地址 if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) { - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId()); - + UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId()); if (defaultUserAddress != null) { userAddressMapper.updateById( - new UserAddressDO() + new UsersUserAddressDO() .setId(defaultUserAddress.getId()) .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) ); } } + // 保存地址 userAddressMapper.insert(userAddressDO); } @Override + @Transactional public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) { - UserAddressDO userAddress = userAddressMapper.selectById(userAddressAddDTO.getId()); - if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); - } + + // 检查地址 + UsersUserAddressDO userAddress = userAddressMapper.selectById(userAddressAddDTO.getId()); if (userAddress == null) { throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); } - // 检查是否设置为默认地址 - if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) { - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId()); + // 删除的地址不能更新 + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); + } + // 检查是否设置为默认地址 + // 是:将数据库 default address 设置为 no + if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) { + UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId()); if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) { userAddressMapper.updateById( - new UserAddressDO() + new UsersUserAddressDO() .setId(defaultUserAddress.getId()) .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) ); } } - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId()); - if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) { - userAddressMapper.updateById( - new UserAddressDO() - .setId(defaultUserAddress.getId()) - .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) - ); - } - - UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + // 转换 vo, 并保存数据 + UsersUserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); userAddressDO.setUpdateTime(new Date()); userAddressMapper.updateById(userAddressDO); } @Override public void removeAddress(Integer userId, Integer addressId) { - UserAddressDO userAddress = userAddressMapper.selectById(addressId); + // checked address is exists. + UsersUserAddressDO userAddress = userAddressMapper.selectById(addressId); + + if (userAddress == null) { + throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); + } if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { // skip return; } - if (userAddress == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); - } - + // 更新状态为 remove userAddressMapper.updateById( - (UserAddressDO) new UserAddressDO() + (UsersUserAddressDO) new UsersUserAddressDO() .setId(addressId) .setDeleted(DeletedStatusEnum.DELETED_YES.getValue()) ); } @Override - public List addressList(Integer userId) { - List userAddressDOList = userAddressMapper.selectByUserId(userId); - - List userAddressBOList = UserAddressConvert - .INSTANCE.convertUserAddressBOList(userAddressDOList); - + public List listAddress(Integer userId) { + List userAddressDOList = userAddressMapper.selectByUserId(userId); + List userAddressBOList = UserAddressConvert.INSTANCE.convertUserAddressBOList(userAddressDOList); return userAddressBOList; } @Override - public UserAddressBO getAddress(Integer userId, Integer id) { - UserAddressDO userAddress = userAddressMapper.selectById(id); - if (userAddress == null) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode()); - } - - if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { - throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); - } - - UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress); - return userAddressBO; + public UserAddressBO getAddress(Integer id) { + UsersUserAddressDO userAddress = userAddressMapper.selectById(id); + return UserAddressConvert.INSTANCE.convert(userAddress); } @Override public UserAddressBO getDefaultAddress(Integer userId) { - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userId); + UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userId); return UserAddressConvert.INSTANCE.convert(defaultUserAddress); } } diff --git a/user/user-rest/pom.xml b/user/user-rest/pom.xml index e5fd87907..88bfd5d54 100644 --- a/user/user-rest/pom.xml +++ b/user/user-rest/pom.xml @@ -13,17 +13,11 @@ - - - - - - - cn.iocoder.mall - common-framework + user-biz 1.0-SNAPSHOT + compile @@ -32,8 +26,16 @@ mall-spring-boot-starter-web 1.0-SNAPSHOT - - + + cn.iocoder.mall + mall-spring-boot-starter-security + 1.0-SNAPSHOT + + + cn.iocoder.mall + mall-spring-boot-starter-swagger + 1.0-SNAPSHOT + diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/controller/user/UsersUserAddressController.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/controller/user/UsersUserAddressController.java new file mode 100644 index 000000000..e4a7db9ad --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/controller/user/UsersUserAddressController.java @@ -0,0 +1,80 @@ +package cn.iocoder.mall.user.rest.controller.user; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.security.core.context.UserSecurityContextHolder; +import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO; +import cn.iocoder.mall.user.biz.service.user.UserAddressService; +import cn.iocoder.mall.user.rest.convert.UserAddressConvert; +import cn.iocoder.mall.user.rest.request.UserAddressAddRequest; +import cn.iocoder.mall.user.rest.request.UserAddressUpdateRequest; +import cn.iocoder.mall.user.rest.response.UserAddressResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 用户地址(user API) + * + * author: sin + * time: 2020/5/8 9:50 + */ +@RestController +@Api(tags = "用户地址(user API)") +@RequestMapping("/users/user-address") +public class UsersUserAddressController { + + @Autowired + private UserAddressService userAddressService; + + @GetMapping("list-address") + @ApiOperation("获取 - 地址列表(all)") + public CommonResult> listAddress() { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.listAddress(userId))); + } + + @GetMapping("{addressId}") + @ApiOperation("获取 - 根据id获取") + public CommonResult getAddress(@PathVariable("addressId") Integer addressId) { + return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.getAddress(addressId))); + } + + @GetMapping("default") + @ApiOperation("获取 - 获取默认地址") + public CommonResult getDefaultAddress() { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId))); + } + + @DeleteMapping("/{addressId}/remove") + @ApiOperation("删除 - 根据id删除") + public CommonResult getDefaultAddress(@PathVariable("addressId") Integer addressId) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + userAddressService.removeAddress(userId, addressId); + return CommonResult.success(null); + } + + @PostMapping("/add-address") + @ApiOperation("添加地址") + public CommonResult addAddress(@RequestBody UserAddressAddRequest userAddressAddRequest) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddRequest); + userAddressAddDTO.setUserId(userId); + userAddressService.addAddress(userAddressAddDTO); + return CommonResult.success(null); + } + + @PutMapping("/update-address") + @ApiOperation("更新地址") + public CommonResult updateAddress(@RequestBody UserAddressUpdateRequest userAddressAddRequest) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + UserAddressUpdateDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddRequest); + userAddressAddDTO.setUserId(userId); + userAddressService.updateAddress(userAddressAddDTO); + return CommonResult.success(null); + } +} diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/convert/UserAddressConvert.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/convert/UserAddressConvert.java new file mode 100644 index 000000000..1a511e03b --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/convert/UserAddressConvert.java @@ -0,0 +1,37 @@ +package cn.iocoder.mall.user.rest.convert; + +import cn.iocoder.mall.user.biz.bo.user.UserAddressBO; +import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO; +import cn.iocoder.mall.user.rest.request.UserAddressAddRequest; +import cn.iocoder.mall.user.rest.request.UserAddressUpdateRequest; +import cn.iocoder.mall.user.rest.response.UserAddressResponse; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 用户地址 convert + * + * author: sin + * time: 2020/5/8 10:01 + */ +@Mapper +public interface UserAddressConvert { + + UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class); + + @Mappings({}) + List convert(List userAddressBOList); + + @Mappings({}) + UserAddressResponse convert(UserAddressBO userAddressBO); + + @Mappings({}) + UserAddressAddDTO convert(UserAddressAddRequest userAddressAddRequest); + + @Mappings({}) + UserAddressUpdateDTO convert(UserAddressUpdateRequest userAddressUpdateRequest); +} diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressAddRequest.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressAddRequest.java new file mode 100644 index 000000000..4a886c15a --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressAddRequest.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.user.rest.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 13:25 + */ +@Data +@Accessors(chain = true) +@ApiModel("用户地址(添加)") +public class UserAddressAddRequest implements Serializable { + + @NotNull + @ApiModelProperty("收件区域编号") + private String areaNo; + + @NotNull + @ApiModelProperty("收件人名称") + private String name; + + @NotNull + @ApiModelProperty("收件手机号") + private String mobile; + + @NotNull + @ApiModelProperty("收件详细地址") + private String address; + + @NotNull + @ApiModelProperty("是否默认 1 不是 2 是") + private Integer hasDefault; +} diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressUpdateRequest.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressUpdateRequest.java new file mode 100644 index 000000000..d9d17ff80 --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/UserAddressUpdateRequest.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.user.rest.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 用户地址 更新 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +@ApiModel("用户地址(更新)") +public class UserAddressUpdateRequest implements Serializable { + + @NotNull + @ApiModelProperty("编号") + private Integer id; + + @NotNull + @ApiModelProperty("收件区域编号") + private String areaNo; + + @NotNull + @ApiModelProperty("收件人名称") + private String name; + + @NotNull + @ApiModelProperty("收件手机号") + private String mobile; + + @NotNull + @ApiModelProperty("收件详细地址") + private String address; + + @NotNull + @ApiModelProperty("是否默认地址") + private Integer hasDefault; +} diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/package-info.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/package-info.java new file mode 100644 index 000000000..bbf91bb60 --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/request/package-info.java @@ -0,0 +1,5 @@ +/** + * author: sin + * time: 2020/5/8 9:57 + */ +package cn.iocoder.mall.user.rest.request; \ No newline at end of file diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/UserAddressResponse.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/UserAddressResponse.java new file mode 100644 index 000000000..5430da824 --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/UserAddressResponse.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.user.rest.response; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "用户地址") +public class UserAddressResponse implements Serializable { + + @ApiModelProperty("编号") + private Integer id; + + @ApiModelProperty("用户编号") + private Integer userId; + + @ApiModelProperty("收件区域编号") + private String areaNo; + + @ApiModelProperty("收件人名称") + private String name; + + @ApiModelProperty("收件手机号") + private String mobile; + + @ApiModelProperty("收件详细地址") + private String address; + + @ApiModelProperty("是否默认") + private Integer hasDefault; +} diff --git a/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/package-info.java b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/package-info.java new file mode 100644 index 000000000..20cf1449a --- /dev/null +++ b/user/user-rest/src/main/java/cn/iocoder/mall/user/rest/response/package-info.java @@ -0,0 +1,5 @@ +/** + * author: sin + * time: 2020/5/8 9:57 + */ +package cn.iocoder.mall.user.rest.response; \ No newline at end of file diff --git a/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java b/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java index cb58c1c4f..409d76d74 100644 --- a/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java +++ b/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java @@ -22,7 +22,7 @@ public interface UserAddressRPC { List addressList(Integer userId); - UserAddressResponse getAddress(Integer userId, Integer id); + UserAddressResponse getAddress(Integer id); UserAddressResponse getDefaultAddress(Integer userId); } diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java index 6feb5d39f..60dea4528 100644 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java +++ b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java @@ -34,12 +34,12 @@ public class UserAddressRPCImpl implements UserAddressRPC { @Override public List addressList(Integer userId) { - return UserAddressRPCConvert.INSTANCE.convert(userAddressService.addressList(userId)); + return UserAddressRPCConvert.INSTANCE.convert(userAddressService.listAddress(userId)); } @Override - public UserAddressResponse getAddress(Integer userId, Integer id) { - return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(userId, id)); + public UserAddressResponse getAddress(Integer id) { + return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(id)); } @Override