mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
mall + product:简化收藏逻辑,去掉 type 字段
This commit is contained in:
parent
25bea4920c
commit
84b365a707
@ -1,36 +0,0 @@
|
||||
package cn.iocoder.yudao.module.product.enums.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
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();
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.product.controller.app.favorite;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
@ -35,21 +36,23 @@ public class AppFavoriteController {
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@PostMapping(value = "/create")
|
||||
@Operation(summary = "商品收藏")
|
||||
//@PreAuthenticated TODO 暂时注释
|
||||
@Operation(summary = "添加商品收藏")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Long> createFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) {
|
||||
return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO));
|
||||
return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO.getSpuId()));
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete")
|
||||
@Operation(summary = "取消商品收藏")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> deleteFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) {
|
||||
productFavoriteService.deleteFavorite(getLoginUserId(), reqVO);
|
||||
productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId());
|
||||
return success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/page")
|
||||
@Operation(summary = "分页获取商品收藏列表")
|
||||
@PreAuthenticated
|
||||
public CommonResult<PageResult<AppFavoriteRespVO>> getFavoritePage(AppFavoritePageReqVO reqVO) {
|
||||
PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO);
|
||||
if (CollUtil.isEmpty(favoritePage.getList())) {
|
||||
@ -67,11 +70,11 @@ public class AppFavoriteController {
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/exits")
|
||||
@Operation(summary = "检查是否收藏过商品")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> isFavoriteExists(AppFavoriteReqVO reqVO) {
|
||||
ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO);
|
||||
ProductFavoriteDO favoriteDO = productFavoriteService.getFavorite(getLoginUserId(), reqVO.getSpuId());
|
||||
return success(Objects.nonNull(favoriteDO));
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,10 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
|
||||
|
||||
@Schema(description = "用户APP - 商品收藏分页查询 Request VO")
|
||||
@Data
|
||||
public class AppFavoritePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "类型", requiredMode = REQUIRED, example = "1")
|
||||
@NotNull(message = "类型不能为空")
|
||||
@InEnum(ProductFavoriteTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@ -17,9 +15,4 @@ public class AppFavoriteReqVO {
|
||||
@NotNull(message = "商品 SPU 编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "类型", requiredMode = REQUIRED, example = "1")
|
||||
@NotNull(message = "类型不能为空")
|
||||
@InEnum(ProductFavoriteTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
@ -14,9 +14,6 @@ public class AppFavoriteRespVO {
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "类型", requiredMode = REQUIRED, example = "1")
|
||||
private Integer type;
|
||||
|
||||
// ========== 商品相关字段 ==========
|
||||
|
||||
@Schema(description = "商品 SPU 名称", example = "赵六")
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.product.convert.favorite;
|
||||
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
@ -19,7 +18,7 @@ public interface ProductFavoriteConvert {
|
||||
|
||||
ProductFavoriteConvert INSTANCE = Mappers.getMapper(ProductFavoriteConvert.class);
|
||||
|
||||
ProductFavoriteDO convert(Long userId, AppFavoriteReqVO reqVO);
|
||||
ProductFavoriteDO convert(Long userId, Long spuId);
|
||||
|
||||
@Mapping(target = "id", source = "favorite.id")
|
||||
@Mapping(target = "spuName", source = "spu.name")
|
||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.dal.dataobject.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.enums.favorite.ProductFavoriteTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@ -40,11 +39,5 @@ public class ProductFavoriteDO extends BaseDO {
|
||||
* 关联 {@link ProductSpuDO#getId()}
|
||||
*/
|
||||
private Long spuId;
|
||||
/**
|
||||
* 类型
|
||||
*
|
||||
* 枚举 {@link ProductFavoriteTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package cn.iocoder.yudao.module.product.dal.mysql.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -11,17 +10,14 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> {
|
||||
|
||||
default ProductFavoriteDO selectByUserAndSpuAndType(Long userId, Long spuId, Integer type) {
|
||||
return selectOne(new LambdaQueryWrapperX<ProductFavoriteDO>()
|
||||
.eq(ProductFavoriteDO::getUserId, userId)
|
||||
.eq(ProductFavoriteDO::getSpuId, spuId)
|
||||
.eq(ProductFavoriteDO::getType, type));
|
||||
default ProductFavoriteDO selectByUserIdAndSpuId(Long userId, Long spuId) {
|
||||
return selectOne(ProductFavoriteDO::getUserId, userId,
|
||||
ProductFavoriteDO::getSpuId, spuId);
|
||||
}
|
||||
|
||||
default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, Integer type, PageParam pageParam) {
|
||||
return selectPage(pageParam, new LambdaQueryWrapper<ProductFavoriteDO>()
|
||||
default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, AppFavoritePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapper<ProductFavoriteDO>()
|
||||
.eq(ProductFavoriteDO::getUserId, userId)
|
||||
.eq(ProductFavoriteDO::getType, type)
|
||||
.orderByDesc(ProductFavoriteDO::getId));
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@ -19,17 +17,17 @@ public interface ProductFavoriteService {
|
||||
* 创建商品收藏
|
||||
*
|
||||
* @param userId 用户 id
|
||||
* @param reqVO 请求 vo
|
||||
* @param spuId SPU 编号
|
||||
*/
|
||||
Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO);
|
||||
Long createFavorite(Long userId, Long spuId);
|
||||
|
||||
/**
|
||||
* 取消商品收藏
|
||||
*
|
||||
* @param userId 用户 id
|
||||
* @param reqVO 请求 vo
|
||||
* @param spuId SPU 编号
|
||||
*/
|
||||
void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO);
|
||||
void deleteFavorite(Long userId, Long spuId);
|
||||
|
||||
/**
|
||||
* 分页查询用户收藏列表
|
||||
@ -43,8 +41,8 @@ public interface ProductFavoriteService {
|
||||
* 获取收藏过商品
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param reqVO 请求 vo
|
||||
* @param spuId SPU 编号
|
||||
*/
|
||||
ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO);
|
||||
ProductFavoriteDO getFavorite(Long userId, Long spuId);
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.product.service.favorite;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
|
||||
import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.favorite.ProductFavoriteMapper;
|
||||
@ -30,22 +29,20 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService {
|
||||
private ProductFavoriteMapper productFavoriteMapper;
|
||||
|
||||
@Override
|
||||
public Long createFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType(
|
||||
userId, reqVO.getSpuId(), reqVO.getType());
|
||||
public Long createFavorite(Long userId, Long spuId) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId);
|
||||
if (Objects.nonNull(favorite)) {
|
||||
throw exception(FAVORITE_EXISTS);
|
||||
}
|
||||
|
||||
ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, reqVO);
|
||||
ProductFavoriteDO entity = ProductFavoriteConvert.INSTANCE.convert(userId, spuId);
|
||||
productFavoriteMapper.insert(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserAndSpuAndType(
|
||||
userId, reqVO.getSpuId(), reqVO.getType());
|
||||
public void deleteFavorite(Long userId, Long spuId) {
|
||||
ProductFavoriteDO favorite = productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId);
|
||||
if (Objects.isNull(favorite)) {
|
||||
throw exception(FAVORITE_NOT_EXISTS);
|
||||
}
|
||||
@ -55,12 +52,12 @@ public class ProductFavoriteServiceImpl implements ProductFavoriteService {
|
||||
|
||||
@Override
|
||||
public PageResult<ProductFavoriteDO> getFavoritePage(Long userId, @Valid AppFavoritePageReqVO reqVO) {
|
||||
return productFavoriteMapper.selectPageByUserAndType(userId, reqVO.getType(), reqVO);
|
||||
return productFavoriteMapper.selectPageByUserAndType(userId, reqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductFavoriteDO getFavorite(Long userId, @Valid AppFavoriteReqVO reqVO) {
|
||||
return productFavoriteMapper.selectByUserAndSpuAndType(userId, reqVO.getSpuId(), reqVO.getType());
|
||||
public ProductFavoriteDO getFavorite(Long userId, Long spuId) {
|
||||
return productFavoriteMapper.selectByUserIdAndSpuId(userId, spuId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user