- 添加用户地址api
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package cn.iocoder.mall.user.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.user.application.convert.UserAddressConvert;
|
||||
import cn.iocoder.mall.user.application.po.UserAddressAddPO;
|
||||
import cn.iocoder.mall.user.application.po.UserAddressUpdatePO;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import cn.iocoder.mall.user.service.api.UserAddressService;
|
||||
import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 用户地址
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-06 14:11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user/address")
|
||||
@Api(description = "用户地址API")
|
||||
public class UserAddressController {
|
||||
|
||||
@Autowired
|
||||
private UserAddressService userAddressService;
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation(value = "用户地址-添加")
|
||||
public CommonResult addAddress(@RequestBody @Validated UserAddressAddPO userAddressAddPO) {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO);
|
||||
userAddressAddDTO.setUserId(userId);
|
||||
return userAddressService.addAddress(userAddressAddDTO);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation(value = "用户地址-更新")
|
||||
public CommonResult updateAddress(@RequestBody @Validated UserAddressUpdatePO userAddressUpdatePO) {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO);
|
||||
userAddressUpdateDTO.setUserId(userId);
|
||||
return userAddressService.updateAddress(userAddressUpdateDTO);
|
||||
}
|
||||
|
||||
@DeleteMapping("remove")
|
||||
@ApiOperation(value = "用户地址-删除")
|
||||
public CommonResult removeAddress(@RequestParam("id") Integer id) {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
return userAddressService.removeAddress(userId, id);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
@ApiOperation(value = "用户地址列表")
|
||||
public CommonResult addressList() {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
return userAddressService.addressList(userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.user.application.convert;
|
||||
|
||||
import cn.iocoder.mall.user.application.po.UserAddressAddPO;
|
||||
import cn.iocoder.mall.user.application.po.UserAddressUpdatePO;
|
||||
import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Sin
|
||||
* @time 2019-04-06 14:19
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserAddressConvert {
|
||||
|
||||
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
UserAddressAddDTO convert(UserAddressAddPO userAddressAddPO);
|
||||
|
||||
@Mappings({})
|
||||
UserAddressUpdateDTO convert(UserAddressUpdatePO userAddressUpdatePO);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package cn.iocoder.mall.user.application.po;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户地址 add
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-06 14:13
|
||||
*/
|
||||
@ApiModel("用户地址")
|
||||
public class UserAddressAddPO implements Serializable {
|
||||
|
||||
/**
|
||||
* 收件区域编号
|
||||
*/
|
||||
@ApiModelProperty("区域编号")
|
||||
@NotNull(message = "区域编号不能为空!")
|
||||
private String areaNo;
|
||||
/**
|
||||
* 收件人名称
|
||||
*/
|
||||
@ApiModelProperty("收件人名称")
|
||||
@NotNull(message = "请填写收人信息!")
|
||||
private String name;
|
||||
/**
|
||||
* 收件手机号
|
||||
*/
|
||||
@ApiModelProperty("收件手机号")
|
||||
@NotNull(message = "手机号为不能为空!")
|
||||
@Size(min = 11, max = 11, message = "手机号为 11 位!")
|
||||
private String mobile;
|
||||
/**
|
||||
* 收件详细地址
|
||||
*/
|
||||
@ApiModelProperty("收件详细地址")
|
||||
@NotNull(message = "详细地址不能为空")
|
||||
@Size(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!")
|
||||
private String address;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserAddressAddPO{" +
|
||||
"areaNo='" + areaNo + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", mobile='" + mobile + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getAreaNo() {
|
||||
return areaNo;
|
||||
}
|
||||
|
||||
public UserAddressAddPO setAreaNo(String areaNo) {
|
||||
this.areaNo = areaNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public UserAddressAddPO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public UserAddressAddPO setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public UserAddressAddPO setAddress(String address) {
|
||||
this.address = address;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package cn.iocoder.mall.user.application.po;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户地址 add
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-06 14:13
|
||||
*/
|
||||
@ApiModel("用户地址-更新")
|
||||
public class UserAddressUpdatePO implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 收件区域编号
|
||||
*/
|
||||
@ApiModelProperty("地址编号")
|
||||
@NotNull(message = "地址编号为空!")
|
||||
private Integer id;
|
||||
/**
|
||||
* 收件区域编号
|
||||
*/
|
||||
@ApiModelProperty("区域编号")
|
||||
@NotNull(message = "区域编号不能为空!")
|
||||
private String areaNo;
|
||||
/**
|
||||
* 收件人名称
|
||||
*/
|
||||
@ApiModelProperty("收件人名称")
|
||||
@NotNull(message = "请填写收人信息!")
|
||||
private String name;
|
||||
/**
|
||||
* 收件手机号
|
||||
*/
|
||||
@ApiModelProperty("收件手机号")
|
||||
@NotNull(message = "手机号为不能为空!")
|
||||
@Size(min = 11, max = 11, message = "手机号为 11 位!")
|
||||
private String mobile;
|
||||
/**
|
||||
* 收件详细地址
|
||||
*/
|
||||
@ApiModelProperty("收件详细地址")
|
||||
@NotNull(message = "详细地址不能为空")
|
||||
@Size(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!")
|
||||
private String address;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserAddressUpdatePO{" +
|
||||
"id=" + id +
|
||||
", areaNo='" + areaNo + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", mobile='" + mobile + '\'' +
|
||||
", address='" + address + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UserAddressUpdatePO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAreaNo() {
|
||||
return areaNo;
|
||||
}
|
||||
|
||||
public UserAddressUpdatePO setAreaNo(String areaNo) {
|
||||
this.areaNo = areaNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public UserAddressUpdatePO setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public UserAddressUpdatePO setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public UserAddressUpdatePO setAddress(String address) {
|
||||
this.address = address;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user