增加 c 端读取商品分类的接口
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user