Parcourir la source

商品浏览记录接口完善

macro il y a 4 ans
Parent
commit
ddcf961e87

+ 8 - 0
mall-portal/src/main/java/com/macro/mall/portal/controller/MemberReadHistoryController.java

@@ -48,6 +48,14 @@ public class MemberReadHistoryController {
         }
     }
 
+    @ApiOperation("清空除浏览记录")
+    @RequestMapping(value = "/clear", method = RequestMethod.POST)
+    @ResponseBody
+    public CommonResult clear() {
+        memberReadHistoryService.clear();
+        return CommonResult.success(null);
+    }
+
     @ApiOperation("分页获取用户浏览记录")
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     @ResponseBody

+ 1 - 0
mall-portal/src/main/java/com/macro/mall/portal/repository/MemberReadHistoryRepository.java

@@ -13,4 +13,5 @@ import java.util.List;
  */
 public interface MemberReadHistoryRepository extends MongoRepository<MemberReadHistory,String> {
     Page<MemberReadHistory> findByMemberIdOrderByCreateTimeDesc(Long memberId, Pageable pageable);
+    void deleteAllByMemberId(Long memberId);
 }

+ 5 - 0
mall-portal/src/main/java/com/macro/mall/portal/service/MemberReadHistoryService.java

@@ -24,4 +24,9 @@ public interface MemberReadHistoryService {
      * 分页获取用户浏览历史记录
      */
     Page<MemberReadHistory> list(Integer pageNum, Integer pageSize);
+
+    /**
+     * 清空浏览记录
+     */
+    void clear();
 }

+ 6 - 0
mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java

@@ -55,4 +55,10 @@ public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
         Pageable pageable = PageRequest.of(pageNum-1, pageSize);
         return memberReadHistoryRepository.findByMemberIdOrderByCreateTimeDesc(member.getId(),pageable);
     }
+
+    @Override
+    public void clear() {
+        UmsMember member = memberService.getCurrentMember();
+        memberReadHistoryRepository.deleteAllByMemberId(member.getId());
+    }
 }