Skip to content

Commit

Permalink
Merge pull request #244 from OutDecision/issue/74
Browse files Browse the repository at this point in the history
[UPDATE] 추천게시글 비로그인시 랜덤
201912160 authored May 28, 2024
2 parents 91938b1 + 6a01f02 commit 3cc4d08
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@@ -30,13 +32,15 @@ public class MainServiceReImpl implements MainServiceRe{
@Override
public PostListReDTO getMainRe() {

Pageable pageable = PageRequest.of(0, 6, Sort.by(Sort.Direction.DESC, "createdAt"));
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "createdAt"));

Long memberId = findMemberService.findLoginMemberId();
//추천 게시물 리스트
List<PostDTO> recommendPostDTOList;
if(memberId==0) {
recommendPostDTOList=mapToDTO(postRepository.findAll(pageable).getContent());
List<Post> posts = new ArrayList<>(postRepository.findAll(pageable).getContent()); // 수정 가능한 리스트로 변환
Collections.shuffle(posts); // 리스트를 랜덤하게 섞음
recommendPostDTOList = mapToDTO(posts);
}
else{
List<Post> recommendPosts = postsService.recommendPost(memberId);
Original file line number Diff line number Diff line change
@@ -165,7 +165,9 @@ public List<Post> recommendPost(Long memberId) {
if (viewList.isEmpty()) {
// 사용자의 조회 기록이 없는 경우, 모든 게시글을 반환
Pageable pageable = PageRequest.of(0, 5); // 페이지와 사이즈 조정
return postRepository.findAll(pageable).getContent();
List<Post> posts = new ArrayList<>(postRepository.findAll(pageable).getContent()); // 수정 가능한 리스트로 변환
Collections.shuffle(posts); // 리스트를 랜덤하게 섞음
return posts;
}

// UserBasedCF를 사용하여 추천 시스템 실행

0 comments on commit 3cc4d08

Please sign in to comment.