Skip to content

Commit

Permalink
[feat] 친구 데이터 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Oct 7, 2023
1 parent 475438f commit 3a3dcae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void configure(WebSecurity webSecurity) {
.antMatchers(
"/friends",
"/api/user/auth/kakao-login",
"/"
"/",
"/api/user/diary/friend-main"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public DiaryRecordResponseDto diaryRecord(
return diaryRecordResponseDto;
}

@GetMapping(value = "/friend-main")
public MainResponseDto friendMainData() {

MainResponseDto mainResponseDto = diaryService.friendMainData();

LOGGER.info("친구 메인 데이터 조회 완료");

return mainResponseDto;
}

@GetMapping(value = "/main")
public MainResponseDto mainData(
@AuthenticationPrincipal CustomUser customUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,48 @@ public DiaryRecordResponseDto diaryRecord(String date, Long userId){
public MainResponseDto mainData(Long userId) {
User user = User.builder().id(userId).build();

MainResponseDto mainResponseDto = new MainResponseDto();
mainResponseDto.setCode(200);
mainResponseDto.setMessage("OK");

List<Diary> diaryList = diaryRepository.findByWriter(user);

List<List<MainResponseDto.UserData>> userDataLists = new ArrayList<>();
List<MainResponseDto.UserData> userDataList = new ArrayList<>();

for (int i = 0; i < diaryList.size(); i++) {
List<DiaryDetail> diaryDetailList = diaryDetailRepository.findByDiary(diaryList.get(i));
MainResponseDto.UserData userData = new MainResponseDto.UserData();

List<String> contentList = diaryDetailList.stream()
.map(DiaryDetail::getContent)
.collect(Collectors.toList());

userData.setGood(diaryList.get(i).getGood());
userData.setContents(contentList);

userDataList.add(userData);

if (userDataList.size() == 7 || i == diaryList.size() - 1) {
userDataLists.add(userDataList);
userDataList = new ArrayList<>();
}
}

mainResponseDto.setData(userDataLists);

return mainResponseDto;
}


public MainResponseDto friendMainData() {

Long userId = 27L;

User user = User.builder().id(userId).build();



MainResponseDto mainResponseDto = new MainResponseDto();
mainResponseDto.setCode(200);
mainResponseDto.setMessage("OK");
Expand Down

0 comments on commit 3a3dcae

Please sign in to comment.