Skip to content

Commit

Permalink
[Refactor/#266] add sync logic in get memberlist who recommend board
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Jeong committed May 24, 2024
1 parent 560c90f commit bf5db06
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.waggle.domain.recommend.application.query;

import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.presentation.dto.RecommendResponse.RecommendationInfo;

import java.util.List;

Expand All @@ -13,6 +12,5 @@ public interface RecommendQueryService {

List<Member> getRecommendingMembers(Long boardId);

RecommendationInfo getRecommendationInfo(Long boardId, String username);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.persistence.dao.RecommendRepository;
import com.example.waggle.domain.recommend.persistence.entity.Recommend;
import com.example.waggle.domain.recommend.presentation.dto.RecommendResponse.RecommendationInfo;
import com.example.waggle.exception.object.general.GeneralException;
import com.example.waggle.exception.object.handler.MemberHandler;
import com.example.waggle.exception.payload.code.ErrorStatus;
Expand Down Expand Up @@ -53,13 +52,5 @@ public List<Member> getRecommendingMembers(Long boardId) {
return byBoardId.stream().map(r -> r.getMember()).collect(Collectors.toList());
}

@Override
public RecommendationInfo getRecommendationInfo(Long boardId, String username) {
return RecommendationInfo.builder()
.isRecommend(checkRecommend(boardId, username))
.recommendCount(countRecommend(boardId))
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.waggle.domain.member.persistence.dao.MemberRepository;
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.recommend.persistence.dao.RecommendRepository;
import com.example.waggle.domain.recommend.presentation.dto.RecommendResponse;
import com.example.waggle.exception.object.handler.MemberHandler;
import com.example.waggle.exception.payload.code.ErrorStatus;
import com.example.waggle.global.service.redis.RedisService;
Expand All @@ -13,7 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -57,19 +55,8 @@ public int countRecommend(Long boardId) {

@Override
public List<Member> getRecommendingMembers(Long boardId) {
List<Member> fromRDB = recommendRepository.findByBoardId(boardId).stream()
return recommendRepository.findByBoardId(boardId).stream()
.map(recommend -> recommend.getMember()).collect(Collectors.toList());
List<Member> fromRedis = redisService.getAllRecommendingMemberList().stream()
.filter(memberId -> redisService.existRecommend(memberId, boardId))
.map(memberRepository::findById)
.filter(Optional::isPresent)
.map(Optional::get).collect(Collectors.toList());
fromRDB.addAll(fromRedis);
return fromRDB;
}

@Override
public RecommendResponse.RecommendationInfo getRecommendationInfo(Long boardId, String username) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.example.waggle.domain.recommend.application.command.RecommendCommandService;
import com.example.waggle.domain.recommend.application.query.RecommendQueryService;
import com.example.waggle.domain.recommend.application.sync.RecommendSyncService;
import com.example.waggle.exception.payload.code.ErrorStatus;
import com.example.waggle.exception.payload.dto.ApiResponseDto;
import com.example.waggle.global.annotation.api.ApiErrorCodeExample;
import com.example.waggle.global.annotation.auth.AuthUser;
import com.example.waggle.exception.payload.dto.ApiResponseDto;
import com.example.waggle.exception.payload.code.ErrorStatus;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -47,6 +47,7 @@ public ApiResponseDto<Long> recommendBoard(@PathVariable("boardId") Long boardId
})
@GetMapping("/{boardId}/memberList")
public ApiResponseDto<MemberSummaryListDto> getRecommendingMembers(@PathVariable("boardId") Long boardId) {
recommendSyncService.syncRecommendation();
List<Member> recommendingMembers = recommendQueryService.getRecommendingMembers(boardId);
return ApiResponseDto.onSuccess(MemberConverter.toMemberListDto(recommendingMembers));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,12 @@ public List<Long> getRecommendedBoardList(Long memberId) {
.map(board -> Long.valueOf(board)).collect(Collectors.toList());
}

// public List<Long> getRecommendingMemberList(Long boardId) {
// SetOperations<String, String> setOperations = redisTemplate.opsForSet();
// String key = recommendBoardKeyPrefix + boardId;
// Set<String> members = setOperations.members(key);
// return members.stream()
// .map(member -> Long.valueOf(member)).collect(Collectors.toList());
// }
public List<Long> getAllInitMemberList() {
Set<String> keysByPattern = getKeysByPattern(initKeyPrefix + "*");
return keysByPattern.stream()
.map(key -> Long.valueOf(key.substring(initKeyPrefix.length())))
.collect(Collectors.toList());
}

public List<Long> getAllRecommendingMemberList() {
Set<String> keysByPattern = getKeysByPattern(recommendMemberKeyPrefix + "*");
Expand Down

0 comments on commit bf5db06

Please sign in to comment.