Commit 84b365a70718f42f36fb405233fe8a8f3fbe4082
1 parent
25bea492
mall + product:简化收藏逻辑,去掉 type 字段
Showing
10 changed files
with
30 additions
and
102 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java deleted
| 1 | -package cn.iocoder.yudao.module.product.enums.favorite; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 4 | -import lombok.AllArgsConstructor; | |
| 5 | -import lombok.Getter; | |
| 6 | - | |
| 7 | -import java.util.Arrays; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 商品收藏的类型枚举 | |
| 11 | - * | |
| 12 | - * @author jason | |
| 13 | - */ | |
| 14 | -@Getter | |
| 15 | -@AllArgsConstructor | |
| 16 | -public enum ProductFavoriteTypeEnum implements IntArrayValuable { | |
| 17 | - | |
| 18 | - COLLECT(1,"收藏"), | |
| 19 | - THUMBS_UP(2, "点赞"); | |
| 20 | - | |
| 21 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductFavoriteTypeEnum::getType).toArray(); | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 类型 | |
| 25 | - */ | |
| 26 | - private final Integer type; | |
| 27 | - /** | |
| 28 | - * 描述 | |
| 29 | - */ | |
| 30 | - private final String desc; | |
| 31 | - | |
| 32 | - @Override | |
| 33 | - public int[] array() { | |
| 34 | - return ARRAYS; | |
| 35 | - } | |
| 36 | -} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.product.controller.app.favorite; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | |
| 6 | 7 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; |
| ... | ... | @@ -35,21 +36,23 @@ public class AppFavoriteController { |
| 35 | 36 | private ProductSpuService productSpuService; |
| 36 | 37 | |
| 37 | 38 | @PostMapping(value = "/create") |
| 38 | - @Operation(summary = "商品收藏") | |
| 39 | - //@PreAuthenticated TODO 暂时注释 | |
| 39 | + @Operation(summary = "添加商品收藏") | |
| 40 | + @PreAuthenticated | |
| 40 | 41 | public CommonResult<Long> createFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) { |
| 41 | - return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO)); | |
| 42 | + return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO.getSpuId())); | |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | @DeleteMapping(value = "/delete") |
| 45 | 46 | @Operation(summary = "取消商品收藏") |
| 47 | + @PreAuthenticated | |
| 46 | 48 | public CommonResult<Boolean> deleteFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) { |
| 47 | - productFavoriteService.deleteFavorite(getLoginUserId(), reqVO); | |
| 49 | + productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId()); | |
| 48 | 50 | return success(Boolean.TRUE); |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | @GetMapping(value = "/page") |
| 52 | 54 | @Operation(summary = "分页获取商品收藏列表") |
| 55 | + @PreAuthenticated | |
| 53 | 56 | public CommonResult<PageResult<AppFavoriteRespVO>> getFavoritePage(AppFavoritePageReqVO reqVO) { |
| 54 | 57 | PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO); |
| 55 | 58 | if (CollUtil.isEmpty(favoritePage.getList())) { |
| ... | ... | @@ -67,11 +70,11 @@ public class AppFavoriteController { |
| 67 | 70 | return success(pageResult); |
| 68 | 71 | } |
| 69 | 72 | |
| 70 | - | |
| 71 | 73 | @GetMapping(value = "/exits") |
| 72 | 74 | @Operation(summary = "检查是否收藏过商品") |
| 75 | + @PreAuthenticated | |
| 73 | 76 | public CommonResult<Boolean> isFavoriteExists(AppFavoriteReqVO reqVO) { |
| 74 | - ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO); | |
| 77 | + ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO.getSpuId()); | |
| 75 | 78 | return success(Objects.nonNull(favoriteDO)); |
| 76 | 79 | } |
| 77 | 80 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.app.favorite.vo; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | -import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; | |
| 6 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | 5 | import lombok.Data; |
| 8 | 6 | |
| 9 | -import javax.validation.constraints.NotNull; | |
| 10 | - | |
| 11 | -import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | |
| 12 | - | |
| 13 | 7 | @Schema(description = "用户APP - 商品收藏分页查询 Request VO") |
| 14 | 8 | @Data |
| 15 | 9 | public class AppFavoritePageReqVO extends PageParam { |
| 16 | - | |
| 17 | - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") | |
| 18 | - @NotNull(message = "类型不能为空") | |
| 19 | - @InEnum(ProductFavoriteTypeEnum.class) | |
| 20 | - private Integer type; | |
| 21 | - | |
| 22 | 10 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.app.favorite.vo; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | -import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; | |
| 5 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 4 | import lombok.Data; |
| 7 | 5 | |
| ... | ... | @@ -17,9 +15,4 @@ public class AppFavoriteReqVO { |
| 17 | 15 | @NotNull(message = "商品 SPU 编号不能为空") |
| 18 | 16 | private Long spuId; |
| 19 | 17 | |
| 20 | - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") | |
| 21 | - @NotNull(message = "类型不能为空") | |
| 22 | - @InEnum(ProductFavoriteTypeEnum.class) | |
| 23 | - private Integer type; | |
| 24 | - | |
| 25 | 18 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java
| ... | ... | @@ -14,9 +14,6 @@ public class AppFavoriteRespVO { |
| 14 | 14 | @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502") |
| 15 | 15 | private Long spuId; |
| 16 | 16 | |
| 17 | - @Schema(description = "类型", requiredMode = REQUIRED, example = "1") | |
| 18 | - private Integer type; | |
| 19 | - | |
| 20 | 17 | // ========== 商品相关字段 ========== |
| 21 | 18 | |
| 22 | 19 | @Schema(description = "商品 SPU 名称", example = "赵六") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java
| 1 | 1 | package cn.iocoder.yudao.module.product.convert.favorite; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO; | |
| 4 | 3 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; |
| 5 | 4 | import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; |
| 6 | 5 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| ... | ... | @@ -19,7 +18,7 @@ public interface ProductFavoriteConvert { |
| 19 | 18 | |
| 20 | 19 | ProductFavoriteConvert INSTANCE = Mappers.getMapper(ProductFavoriteConvert.class); |
| 21 | 20 | |
| 22 | - ProductFavoriteDO convert(Long userId, AppFavoriteReqVO reqVO); | |
| 21 | + ProductFavoriteDO convert(Long userId, Long spuId); | |
| 23 | 22 | |
| 24 | 23 | @Mapping(target = "id", source = "favorite.id") |
| 25 | 24 | @Mapping(target = "spuName", source = "spu.name") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.dal.dataobject.favorite; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | 4 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 5 | -import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum; | |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 7 | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
| 8 | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -40,11 +39,5 @@ public class ProductFavoriteDO extends BaseDO { |
| 40 | 39 | * 关联 {@link ProductSpuDO#getId()} |
| 41 | 40 | */ |
| 42 | 41 | private Long spuId; |
| 43 | - /** | |
| 44 | - * 类型 | |
| 45 | - * | |
| 46 | - * 枚举 {@link ProductFavoriteTypeEnum} | |
| 47 | - */ | |
| 48 | - private Integer type; | |
| 49 | 42 | |
| 50 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.product.dal.mysql.favorite; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | +import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; |
| 8 | 7 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 9 | 8 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -11,17 +10,14 @@ import org.apache.ibatis.annotations.Mapper; |
| 11 | 10 | @Mapper |
| 12 | 11 | public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> { |
| 13 | 12 | |
| 14 | - default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) { | |
| 15 | - return selectOne(new LambdaQueryWrapperX<ProductFavoriteDO>() | |
| 16 | - .eq(ProductFavoriteDO::getUserId, userId) | |
| 17 | - .eq(ProductFavoriteDO::getSpuId, spuId) | |
| 18 | - .eq(ProductFavoriteDO::getType, type)); | |
| 13 | + default ProductFavoriteDO selectByUserIdAndSpuId(Long userId, Long spuId) { | |
| 14 | + return selectOne(ProductFavoriteDO::getUserId, userId, | |
| 15 | + ProductFavoriteDO::getSpuId, spuId); | |
| 19 | 16 | } |
| 20 | 17 | |
| 21 | - default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, Integer type, PageParam pageParam) { | |
| 22 | - return selectPage(pageParam, new LambdaQueryWrapper<ProductFavoriteDO>() | |
| 18 | + default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, AppFavoritePageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapper<ProductFavoriteDO>() | |
| 23 | 20 | .eq(ProductFavoriteDO::getUserId, userId) |
| 24 | - .eq(ProductFavoriteDO::getType, type) | |
| 25 | 21 | .orderByDesc(ProductFavoriteDO::getId)); |
| 26 | 22 | } |
| 27 | 23 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteService.java
| ... | ... | @@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; |
| 5 | -import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO; | |
| 6 | -import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO; | |
| 7 | 5 | import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; |
| 8 | 6 | |
| 9 | 7 | import javax.validation.Valid; |
| ... | ... | @@ -19,17 +17,17 @@ public interface ProductFavoriteService { |
| 19 | 17 | * 创建商品收藏 |
| 20 | 18 | * |
| 21 | 19 | * @param userId 用户 id |
| 22 | - * @param reqVO 请求 vo | |
| 20 | + * @param spuId SPU 编号 | |
| 23 | 21 | */ |
| 24 | - Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); | |
| 22 | + Long createFavorite(Long userId, Long spuId); | |
| 25 | 23 | |
| 26 | 24 | /** |
| 27 | 25 | * 取消商品收藏 |
| 28 | 26 | * |
| 29 | 27 | * @param userId 用户 id |
| 30 | - * @param reqVO 请求 vo | |
| 28 | + * @param spuId SPU 编号 | |
| 31 | 29 | */ |
| 32 | - void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); | |
| 30 | + void deleteFavorite(Long userId, Long spuId); | |
| 33 | 31 | |
| 34 | 32 | /** |
| 35 | 33 | * 分页查询用户收藏列表 |
| ... | ... | @@ -43,8 +41,8 @@ public interface ProductFavoriteService { |
| 43 | 41 | * 获取收藏过商品 |
| 44 | 42 | * |
| 45 | 43 | * @param userId 用户id |
| 46 | - * @param reqVO 请求 vo | |
| 44 | + * @param spuId SPU 编号 | |
| 47 | 45 | */ |
| 48 | - ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO); | |
| 46 | + ProductFavoriteDO getFavorite(Long userId, Long spuId); | |
| 49 | 47 | |
| 50 | 48 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO; |
| 5 | -import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert; |
| 7 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO; |
| 8 | 7 | import cn.iocoder.yudao.module.product.dal.mysql.favorite.ProductFavoriteMapper; |
| ... | ... | @@ -30,22 +29,20 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { |
| 30 | 29 | private ProductFavoriteMapper productFavoriteMapper; |
| 31 | 30 | |
| 32 | 31 | @Override |
| 33 | - public Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { | |
| 34 | - ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType( | |
| 35 | - userId, reqVO.getSpuId(), reqVO.getType()); | |
| 32 | + public Long createFavorite(Long userId, Long spuId) { | |
| 33 | + ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); | |
| 36 | 34 | if (Objects.nonNull(favorite)) { |
| 37 | 35 | throw exception(FAVORITE_EXISTS); |
| 38 | 36 | } |
| 39 | 37 | |
| 40 | - ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO); | |
| 38 | + ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, spuId); | |
| 41 | 39 | productFavoriteMapper.insert(entity); |
| 42 | 40 | return entity.getId(); |
| 43 | 41 | } |
| 44 | 42 | |
| 45 | 43 | @Override |
| 46 | - public void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { | |
| 47 | - ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType( | |
| 48 | - userId, reqVO.getSpuId(), reqVO.getType()); | |
| 44 | + public void deleteFavorite(Long userId, Long spuId) { | |
| 45 | + ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); | |
| 49 | 46 | if (Objects.isNull(favorite)) { |
| 50 | 47 | throw exception(FAVORITE_NOT_EXISTS); |
| 51 | 48 | } |
| ... | ... | @@ -55,12 +52,12 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { |
| 55 | 52 | |
| 56 | 53 | @Override |
| 57 | 54 | public PageResult<ProductFavoriteDO> getFavoritePage(Long userId, @Valid AppFavoritePageReqVO reqVO) { |
| 58 | - return productFavoriteMapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO); | |
| 55 | + return productFavoriteMapper.selectPageByUserAndType(userId, reqVO); | |
| 59 | 56 | } |
| 60 | 57 | |
| 61 | 58 | @Override |
| 62 | - public ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) { | |
| 63 | - return productFavoriteMapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); | |
| 59 | + public ProductFavoriteDO getFavorite(Long userId, Long spuId) { | |
| 60 | + return productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId); | |
| 64 | 61 | } |
| 65 | 62 | |
| 66 | 63 | } | ... | ... |