增加 c 端读取商品分类的接口
This commit is contained in:
parent
24f3e697b8
commit
de81e5f5ae
@ -25,6 +25,10 @@ public class InEnumValidator implements ConstraintValidator<InEnum, Integer> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
// 为空时,默认不校验,即认为通过
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
// 校验通过
|
||||
if (values.contains(value)) {
|
||||
return true;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.common.framework.validator;
|
||||
|
||||
import cn.iocoder.common.framework.util.StringUtils;
|
||||
import cn.iocoder.common.framework.util.ValidationUtil;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
@ -13,6 +14,11 @@ public class MobileValidator implements ConstraintValidator<Mobile, String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
// 如果手机号为空,默认不校验,即校验通过
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return true;
|
||||
}
|
||||
// 校验手机
|
||||
return ValidationUtil.isMobile(value);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ -16,5 +18,10 @@ public class ProductCategoryListQueryReqDTO implements Serializable {
|
||||
* 父编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
@ -29,6 +30,7 @@ public interface ProductBrandConvert {
|
||||
|
||||
List<ProductBrandBO> convertList(List<ProductBrandDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductBrandBO> convertPage(IPage<ProductBrandDO> page);
|
||||
|
||||
ProductBrandCreateBO convert(ProductBrandCreateReqDTO bean);
|
||||
@ -42,4 +44,5 @@ public interface ProductBrandConvert {
|
||||
ProductBrandPageBO convert(ProductBrandPageReqDTO bean);
|
||||
|
||||
PageResult<ProductBrandRespDTO> convertPage(PageResult<ProductBrandBO> page);
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
}
|
||||
|
||||
default List<ProductCategoryDO> selectList(ProductCategoryListQueryBO listQueryBO) {
|
||||
return selectList(new QueryWrapperX<ProductCategoryDO>().eqIfPresent("pid", listQueryBO.getPid()));
|
||||
return selectList(new QueryWrapperX<ProductCategoryDO>().eqIfPresent("pid", listQueryBO.getPid())
|
||||
.eqIfPresent("status", listQueryBO.getStatus()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ -14,5 +16,10 @@ public class ProductCategoryListQueryBO {
|
||||
* 父编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ dubbo:
|
||||
ProductCategoryRpc:
|
||||
version: 1.0.0
|
||||
ProductBrandRpc:
|
||||
verion: 1.0.0
|
||||
version: 1.0.0
|
||||
# Dubbo 服务消费者的配置
|
||||
consumer:
|
||||
ErrorCodeRpc:
|
||||
|
@ -53,6 +53,12 @@
|
||||
<artifactId>user-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- 商品服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- 系统服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
|
@ -0,0 +1,4 @@
|
||||
### /user-address/get-default 成功
|
||||
GET {{user-api-base-url}}/product-category/list?pid=0
|
||||
|
||||
###
|
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.userweb.controller.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO;
|
||||
import cn.iocoder.mall.userweb.manager.product.ProductCategoryManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品分类 Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product-category")
|
||||
@Api(tags = "商品分类")
|
||||
@Validated
|
||||
// TODO 芋艿:稍后迁移到 shop-web-app 服务下
|
||||
public class ProductCategoryController {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryManager productCategoryManager;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得商品分类的列表")
|
||||
@ApiImplicitParam(name = "pid", value = "父分类编号", required = true, example = "1024")
|
||||
public CommonResult<List<ProductCategoryRespVO>> listProductCategories(@RequestParam("pid") Integer pid) {
|
||||
return success(productCategoryManager.listProductCategories(pid));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.mall.userweb.controller.product.vo.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("商品分类 Response VO")
|
||||
@Data
|
||||
public class ProductCategoryRespVO {
|
||||
|
||||
@ApiModelProperty(value = "分类编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "分类名称", required = true, example = "手机")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/xx.jpg")
|
||||
private String picUrl;
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
package cn.iocoder.mall.userweb.controller.product.vo;
|
@ -6,11 +6,10 @@ import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO;
|
||||
import cn.iocoder.mall.userweb.manager.user.UserManager;
|
||||
import cn.iocoder.security.annotations.RequiresAuthenticate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@ -25,31 +24,27 @@ public class UserController {
|
||||
@ApiOperation(value = "用户信息")
|
||||
@GetMapping("/info")
|
||||
@RequiresAuthenticate
|
||||
public CommonResult<UserRespVO> info() {
|
||||
public CommonResult<UserRespVO> getUserInfo() {
|
||||
UserRespVO user = userManager.getUser(UserSecurityContextHolder.getUserId());
|
||||
return success(user);
|
||||
}
|
||||
|
||||
// @PostMapping("/update_avatar")
|
||||
// @RequiresLogin
|
||||
// @ApiOperation(value = "更新头像")
|
||||
// public CommonResult<Boolean> updateAvatar(@RequestParam("avatar") String avatar) {
|
||||
// // 创建
|
||||
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
|
||||
// .setAvatar(avatar);
|
||||
// // 更新头像
|
||||
// return success(userService.updateUser(userUpdateDTO));
|
||||
// }
|
||||
@PostMapping("/update-avatar")
|
||||
@RequiresAuthenticate
|
||||
@ApiOperation(value = "更新头像")
|
||||
@ApiImplicitParam(name = "avatar", value = "头像", required = true, example = "http://www.iocoder.cn/xxx.png")
|
||||
public CommonResult<Boolean> updateUserAvatar(@RequestParam("avatar") String avatar) {
|
||||
userManager.updateUserAvatar(UserSecurityContextHolder.getUserId(), avatar);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
// @PostMapping("/update_nickname")
|
||||
// @RequiresLogin
|
||||
// @ApiOperation(value = "更新昵称")
|
||||
// public CommonResult<Boolean> updateNickname(@RequestParam("nickname") String nickname) {
|
||||
// // 创建
|
||||
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
|
||||
// .setNickname(nickname);
|
||||
// // 更新头像
|
||||
// return success(userService.updateUser(userUpdateDTO));
|
||||
// }
|
||||
@PostMapping("/update-nickname")
|
||||
@RequiresAuthenticate
|
||||
@ApiOperation(value = "更新昵称")
|
||||
@ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "蠢艿艿")
|
||||
public CommonResult<Boolean> updateUserNickname(@RequestParam("nickname") String nickname) {
|
||||
userManager.updateUserNickname(UserSecurityContextHolder.getUserId(), nickname);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.userweb.convert.product;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
List<ProductCategoryRespVO> convertList(List<ProductCategoryRespDTO> list);
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.userweb.manager.product;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.userweb.controller.product.vo.category.ProductCategoryRespVO;
|
||||
import cn.iocoder.mall.userweb.convert.product.ProductCategoryConvert;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Product 分类 Manager
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductCategoryManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.ProductCategoryRpc.version}")
|
||||
private ProductCategoryRpc productCategoryRpc;
|
||||
|
||||
public List<ProductCategoryRespVO> listProductCategories(Integer pid) {
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategoriesResult = productCategoryRpc.listProductCategories(
|
||||
new ProductCategoryListQueryReqDTO().setPid(pid).setStatus(CommonStatusEnum.ENABLE.getValue()));
|
||||
listProductCategoriesResult.checkError();
|
||||
return ProductCategoryConvert.INSTANCE.convertList(listProductCategoriesResult.getData());
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package cn.iocoder.mall.userweb.manager.user;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||
import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO;
|
||||
import cn.iocoder.mall.userweb.convert.user.UserConvert;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
@ -20,4 +21,14 @@ public class UserManager {
|
||||
return UserConvert.INSTANCE.convert(userResult.getData());
|
||||
}
|
||||
|
||||
public void updateUserAvatar(Integer userId, String avatar) {
|
||||
CommonResult<Boolean> updateUserResult = userRpc.updateUser(new UserUpdateReqDTO().setId(userId).setAvatar(avatar));
|
||||
updateUserResult.checkError();
|
||||
}
|
||||
|
||||
public void updateUserNickname(Integer userId, String nickname) {
|
||||
CommonResult<Boolean> updateUserResult = userRpc.updateUser(new UserUpdateReqDTO().setId(userId).setNickname(nickname));
|
||||
updateUserResult.checkError();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ dubbo:
|
||||
version: 1.0.0
|
||||
UserAddressRpc:
|
||||
version: 1.0.0
|
||||
ProductCategoryRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
Loading…
Reference in New Issue
Block a user