商品关注、收藏接口完善

This commit is contained in:
macro 2020-06-27 10:34:24 +08:00
parent ddcf961e87
commit 3056a0aa75
8 changed files with 79 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package com.macro.mall.portal.controller;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.MemberBrandAttention;
import com.macro.mall.portal.domain.MemberProductCollection;
import com.macro.mall.portal.service.MemberAttentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -55,4 +56,20 @@ public class MemberAttentionController {
Page<MemberBrandAttention> page = memberAttentionService.list(pageNum,pageSize);
return CommonResult.success(CommonPage.restPage(page));
}
@ApiOperation("显示关注品牌详情")
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@ResponseBody
public CommonResult<MemberBrandAttention> detail(@RequestParam Long brandId) {
MemberBrandAttention memberBrandAttention = memberAttentionService.detail(brandId);
return CommonResult.success(memberBrandAttention);
}
@ApiOperation("清空关注列表")
@RequestMapping(value = "/clear", method = RequestMethod.POST)
@ResponseBody
public CommonResult clear() {
memberAttentionService.clear();
return CommonResult.success(null);
}
}

View File

@ -48,7 +48,7 @@ public class MemberProductCollectionController {
}
}
@ApiOperation("显示关注列表")
@ApiOperation("显示收藏列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<MemberProductCollection>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@ -56,4 +56,20 @@ public class MemberProductCollectionController {
Page<MemberProductCollection> page = memberCollectionService.list(pageNum,pageSize);
return CommonResult.success(CommonPage.restPage(page));
}
@ApiOperation("显示收藏商品详情")
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@ResponseBody
public CommonResult<MemberProductCollection> detail(@RequestParam Long productId) {
MemberProductCollection memberProductCollection = memberCollectionService.detail(productId);
return CommonResult.success(memberProductCollection);
}
@ApiOperation("清空收藏列表")
@RequestMapping(value = "/clear", method = RequestMethod.POST)
@ResponseBody
public CommonResult clear() {
memberCollectionService.clear();
return CommonResult.success(null);
}
}

View File

@ -15,4 +15,5 @@ public interface MemberBrandAttentionRepository extends MongoRepository<MemberBr
MemberBrandAttention findByMemberIdAndBrandId(Long memberId, Long brandId);
int deleteByMemberIdAndBrandId(Long memberId,Long brandId);
Page<MemberBrandAttention> findByMemberId(Long memberId, Pageable pageable);
void deleteAllByMemberId(Long memberId);
}

View File

@ -15,4 +15,5 @@ public interface MemberProductCollectionRepository extends MongoRepository<Membe
MemberProductCollection findByMemberIdAndProductId(Long memberId, Long productId);
int deleteByMemberIdAndProductId(Long memberId,Long productId);
Page<MemberProductCollection> findByMemberId(Long memberId, Pageable pageable);
void deleteAllByMemberId(Long memberId);
}

View File

@ -23,5 +23,15 @@ public interface MemberAttentionService {
/**
* 获取用户关注列表
*/
Page<MemberBrandAttention> list(Integer pageNum,Integer pageSize);
Page<MemberBrandAttention> list(Integer pageNum, Integer pageSize);
/**
* 获取用户关注详情
*/
MemberBrandAttention detail(Long brandId);
/**
* 清空关注列表
*/
void clear();
}

View File

@ -15,4 +15,8 @@ public interface MemberCollectionService {
int delete(Long productId);
Page<MemberProductCollection> list(Integer pageNum, Integer pageSize);
MemberProductCollection detail(Long productId);
void clear();
}

View File

@ -11,6 +11,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
@ -31,6 +32,7 @@ public class MemberAttentionServiceImpl implements MemberAttentionService {
memberBrandAttention.setMemberId(member.getId());
memberBrandAttention.setMemberNickname(member.getNickname());
memberBrandAttention.setMemberIcon(member.getIcon());
memberBrandAttention.setCreateTime(new Date());
MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId());
if (findAttention == null) {
memberBrandAttentionRepository.save(memberBrandAttention);
@ -51,4 +53,16 @@ public class MemberAttentionServiceImpl implements MemberAttentionService {
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
return memberBrandAttentionRepository.findByMemberId(member.getId(),pageable);
}
@Override
public MemberBrandAttention detail(Long brandId) {
UmsMember member = memberService.getCurrentMember();
return memberBrandAttentionRepository.findByMemberIdAndBrandId(member.getId(), brandId);
}
@Override
public void clear() {
UmsMember member = memberService.getCurrentMember();
memberBrandAttentionRepository.deleteAllByMemberId(member.getId());
}
}

View File

@ -48,7 +48,19 @@ public class MemberCollectionServiceImpl implements MemberCollectionService {
@Override
public Page<MemberProductCollection> list(Integer pageNum, Integer pageSize) {
UmsMember member = memberService.getCurrentMember();
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
return productCollectionRepository.findByMemberId(member.getId(),pageable);
Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
return productCollectionRepository.findByMemberId(member.getId(), pageable);
}
@Override
public MemberProductCollection detail(Long productId) {
UmsMember member = memberService.getCurrentMember();
return productCollectionRepository.findByMemberIdAndProductId(member.getId(), productId);
}
@Override
public void clear() {
UmsMember member = memberService.getCurrentMember();
productCollectionRepository.deleteAllByMemberId(member.getId());
}
}