diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index 4338103b4..5c36a2328 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -48,7 +48,7 @@ public interface ErrorCodeConstants { ErrorCode COMMENT_ERROR_OPT = new ErrorCode(1008007002, "商品评价非法操作"); ErrorCode COMMENT_ADDITIONAL_EXISTS = new ErrorCode(1008007003, "商品追加评价已存在"); - // ========== 喜爱商品 1008008000 ========== + // ========== 商品 收藏 1008008000 ========== ErrorCode COLLECTION_EXISTS = new ErrorCode(1008008000, "该商品已经被收藏"); ErrorCode COLLECTION_NOT_EXISTS = new ErrorCode(1008008001, "商品收藏不存在"); diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java index 3dee472fb..4d28ae8ae 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/favorite/ProductFavoriteTypeEnum.java @@ -7,17 +7,19 @@ import lombok.Getter; import java.util.Arrays; /** - * 喜爱商品类型 枚举 + * 商品收藏的类型枚举 * * @author jason */ @Getter @AllArgsConstructor public enum ProductFavoriteTypeEnum implements IntArrayValuable { + COLLECT(1,"收藏"), THUMBS_UP(2, "点赞"); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductFavoriteTypeEnum::getType).toArray(); + /** * 类型 */ diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java index 385cde3ec..9d1d53dd3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/AppFavoriteController.java @@ -18,10 +18,7 @@ import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum.COLLECT; -/** - * @author jason - */ -@Tag(name = "用户 APP - 喜爱商品") +@Tag(name = "用户 APP - 商品收藏") @RestController @RequestMapping("/product/favorite") public class AppFavoriteController { @@ -29,6 +26,7 @@ public class AppFavoriteController { @Resource private ProductFavoriteService productFavoriteService; + // TODO @jason:创建;create @PostMapping(value = "/collect") @Operation(summary = "商品收藏") public CommonResult collect(@RequestBody @Valid AppFavoriteReqVO reqVO) { @@ -36,16 +34,22 @@ public class AppFavoriteController { return success(productFavoriteService.collect(reqVO)); } + // TODO @jason:创建;delete;使用 @DeleteMapping @PostMapping(value = "/cancelCollect") @Operation(summary = "取消商品收藏(通过商品详情)") public CommonResult cancelCollect(@RequestBody @Valid AppFavoriteReqVO reqVO) { + // TODO @jason:是不是不用校验呀? Assert.isTrue(Objects.equals(COLLECT.getType(), reqVO.getType()), "参数type 不匹配"); return success(productFavoriteService.cancelCollect(reqVO)); } + // TODO @jason:page;分页 @GetMapping(value = "/collectList") @Operation(summary = "商品收藏列表") public CommonResult> pageCollectList(AppFavoritePageReqVO reqVO) { return success(productFavoriteService.pageCollectList(reqVO)); } + + // TODO @json:需要在给一个,用户查询某个商品是否收藏;详情页要用 + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java index ef68cb736..3ca8b6da6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoritePageReqVO.java @@ -10,15 +10,13 @@ import javax.validation.constraints.NotNull; import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; -/** - * @author jason - */ -@Schema(description = "用户APP - 喜爱商品分页查询 Request VO") +@Schema(description = "用户APP - 商品收藏分页查询 Request VO") @Data public class AppFavoritePageReqVO extends PageParam { - @Schema(description = "类型 1:收藏 2:点赞", requiredMode = REQUIRED, example = "1") + @Schema(description = "类型", requiredMode = REQUIRED, example = "1") @NotNull(message = "类型不能为空") @InEnum(ProductFavoriteTypeEnum.class) private Integer type; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java index b611922cc..d4f2ba760 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteReqVO.java @@ -9,21 +9,17 @@ import javax.validation.constraints.NotNull; import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; - - -/** - * @author jason - */ -@Schema(description = "用户APP - 喜爱商品创建 Request VO") +@Schema(description = "用户 APP - 商品收藏创建 Request VO") @Data public class AppFavoriteReqVO { - @Schema(description = "商品SPU编号", requiredMode = REQUIRED, example = "29502") - @NotNull(message = "商品SPU编号不能为空") + @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502") + @NotNull(message = "商品 SPU 编号不能为空") private Long spuId; - @Schema(description = "类型 1:收藏 2:点赞", requiredMode = REQUIRED, example = "1") + @Schema(description = "类型", requiredMode = REQUIRED, example = "1") @NotNull(message = "类型不能为空") @InEnum(ProductFavoriteTypeEnum.class) private Integer type; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java index b15c49a62..686a24d6d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/favorite/vo/AppFavoriteRespVO.java @@ -1,23 +1,27 @@ package cn.iocoder.yudao.module.product.controller.app.favorite.vo; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -/** - * @author jason - */ -@Schema(description = "用户APP - 喜爱商品 Response VO") +@Schema(description = "用户APP - 商品收藏 Response VO") @Data public class AppFavoriteRespVO { + // TODO @jason:required true 哈 @Schema(description = "编号", example = "1") private Long id; - @Schema(description = "商品SPU编号", example = "29502") + // TODO @jason:required true 哈 + @Schema(description = "商品 SPU 编号", example = "29502") private Long spuId; - @Schema(description = "商品SPU名称", example = "赵六") + // TODO @jason:required true 哈 + @Schema(description = "类型", example = "1") + private Integer type; + + // ========== 商品相关字段 ========== + + @Schema(description = "商品 SPU 名称", example = "赵六") private String spuName; @Schema(description = "商品封面图", example = "https://domain/pic.png") @@ -26,6 +30,4 @@ public class AppFavoriteRespVO { @Schema(description = "商品单价", example = "100") private Integer price; - @Schema(description = "类型 1:收藏 2:点赞", example = "1") - private Integer type; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java index 04b6dc56a..03fb1caf9 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/favorite/ProductFavoriteConvert.java @@ -5,11 +5,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -/** - * 喜爱商品 Convert - * - * @author jason - */ @Mapper public interface ProductFavoriteConvert { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java index 20b712aff..356bba065 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/favorite/ProductFavoriteDO.java @@ -20,7 +20,7 @@ import lombok.*; @Builder @NoArgsConstructor @AllArgsConstructor -public class ProductFavoriteDO extends TenantBaseDO { +public class ProductFavoriteDO extends TenantBaseDO { // TODO @jason:如无必要,使用 BaseDO 哈。例如说 tenant_id 在业务里,是否需要使用到 /** * 编号,主键自增 @@ -40,7 +40,7 @@ public class ProductFavoriteDO extends TenantBaseDO { */ private Long spuId; /** - * 类型 1 收藏;2 点赞 + * 类型 1 收藏;2 点赞 // TODO @jason:不要注释 1 收藏 2 点赞;而是注释好,它对应的枚举类 */ private Integer type; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java index e9ee46a7f..435152ea7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/favorite/ProductFavoriteMapper.java @@ -12,15 +12,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -/** - * 喜爱商品 Mapper - * - * @author jason - */ @Mapper public interface ProductFavoriteMapper extends BaseMapperX { - default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type){ + default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) { Assert.notNull(userId, "the userId argument must not be null"); Assert.notNull(spuId, "the spuId argument must not be null"); Assert.notNull(type, "the type argument must not be null"); @@ -36,6 +31,7 @@ public interface ProductFavoriteMapper extends BaseMapperX { return new PageResult<>(page.getRecords(), page.getTotal()); } + // TODO @jason:内存中拼接哈。这样好兼容更多的 db 类型; Page selectFavoriteProductList(Page page, @Param("userId") Long userId, @Param("type") Integer type); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java index 1b295157c..8300cbc8c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/favorite/ProductFavoriteServiceImpl.java @@ -20,7 +20,7 @@ import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.COLLECTIO import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.COLLECTION_NOT_EXISTS; /** - * 喜爱商品 Service 实现类 + * 商品收藏 Service 实现类 * * @author jason */ @@ -33,11 +33,15 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { @Override public Boolean collect(@Valid AppFavoriteReqVO reqVO) { + // TODO @jason:userId 要从 Controller 传递过来,Service 不能有转台 Long userId = getLoginUserId(); + // TODO @jason:代码缩进不对; ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType()); if (Objects.nonNull(favoriteDO)) { throw exception(COLLECTION_EXISTS); } + + // TODO @jason:插入只有成功,不用判断 1 ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO); int count = mapper.insert(entity); return count == 1; @@ -45,11 +49,13 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { @Override public Boolean cancelCollect(@Valid AppFavoriteReqVO reqVO) { + // TODO @jason:代码缩进不对; Long loginUserId = getLoginUserId(); ProductFavoriteDO favoriteDO = mapper.selectByUserAndSpuAndType(loginUserId, reqVO.getSpuId(), reqVO.getType()); if (Objects.isNull(favoriteDO)) { throw exception(COLLECTION_NOT_EXISTS); } + // TODO @jason:插入只有成功,不用判断 1 int count = mapper.deleteById(favoriteDO.getId()); return count == 1; } @@ -59,4 +65,5 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService { Long userId = getLoginUserId(); return mapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO); } + }