| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.mall.dto.AddCollectionDto; |
| | |
| | | private final IApiMallGoodsService apiMallGoodsService; |
| | | |
| | | @Override |
| | | public void add(AddCollectionDto addCollectionDto) { |
| | | public FebsResponse add(AddCollectionDto addCollectionDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | MallGoods mallgoods = apiMallGoodsService.getById(addCollectionDto.getGoodsId()); |
| | | if (mallgoods == null) { |
| | | throw new FebsException("商品不存在"); |
| | | throw new FebsException("The product does not exist."); |
| | | } |
| | | |
| | | LambdaQueryWrapper<MallMemberCollection> queryWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | queryWrapper.eq(MallMemberCollection::getGoodsId, addCollectionDto.getGoodsId()); |
| | | List<MallMemberCollection> mallMemberCollections = this.baseMapper.selectList(queryWrapper); |
| | | if (CollUtil.isNotEmpty(mallMemberCollections)) { |
| | | throw new FebsException("商品已收藏"); |
| | | throw new FebsException("Product has been favorited"); |
| | | } |
| | | |
| | | MallMemberCollection collection = new MallMemberCollection(); |
| | | collection.setMemberId(member.getId()); |
| | | collection.setGoodsId(addCollectionDto.getGoodsId()); |
| | | |
| | | this.baseMapper.insert(collection); |
| | | |
| | | return new FebsResponse().success().message("Added to favorites"); |
| | | } |
| | | |
| | | @Override |