From a35b704dce5dc63a2e856a7c09fbd7e9f70559df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?toni=20=28=EC=9D=B4=EC=86=8C=EC=9D=80=29?= <144209738+saokiritoni@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:40:41 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=ED=94=BC=EB=93=9C=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goal/controller/FeedController.java | 5 +-- .../domain/goal/service/GoalService.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/dongguk/osori/domain/goal/controller/FeedController.java b/src/main/java/dongguk/osori/domain/goal/controller/FeedController.java index eb3388d..b6712a3 100644 --- a/src/main/java/dongguk/osori/domain/goal/controller/FeedController.java +++ b/src/main/java/dongguk/osori/domain/goal/controller/FeedController.java @@ -27,15 +27,16 @@ public class FeedController { @ApiResponse(responseCode = "401", description = "인증되지 않은 사용자") }) @GetMapping - public ResponseEntity> getTodayFeedGoals(HttpSession session) { + public ResponseEntity> getTodayFeedGoals(HttpSession session) { Long userId = (Long) session.getAttribute("userId"); if (userId == null) { return ResponseEntity.status(401).build(); } - List feedGoals = goalService.getTodayFeedGoals(userId); + List feedGoals = goalService.getTodayFeedGoalsAsDetails(userId); return ResponseEntity.ok(feedGoals); } + @Operation(summary = "단일 목표 상세 조회", description = "단일 목표와 그에 달린 모든 댓글을 조회합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "목표 상세 조회 성공"), diff --git a/src/main/java/dongguk/osori/domain/goal/service/GoalService.java b/src/main/java/dongguk/osori/domain/goal/service/GoalService.java index dcc5e7c..871a937 100644 --- a/src/main/java/dongguk/osori/domain/goal/service/GoalService.java +++ b/src/main/java/dongguk/osori/domain/goal/service/GoalService.java @@ -132,6 +132,38 @@ public List getTodayFeedGoals(Long userId) { .collect(Collectors.toList()); } + + @Transactional + public List getTodayFeedGoalsAsDetails(Long userId) { + User loggedInUser = getLoggedInUser(userId); // 로그인된 사용자 가져오기 + LocalDateTime startOfDay = LocalDate.now().atStartOfDay(); + LocalDateTime endOfDay = startOfDay.plusDays(1); + + List followingUsers = loggedInUser.getFollowingUsers(); // 팔로우한 사용자 목록 가져오기 + + // 오늘 날짜에 생성된 팔로우한 사용자의 목표 조회 + return goalRepository.findByUserInAndCreatedAtBetween(followingUsers, startOfDay, endOfDay) + .stream() + .map(goal -> new GoalDetailResponseDto( + goal.getGoalId(), + goal.getContent(), + goal.getUser().getNickname(), + goal.getCreatedAt(), + goal.isCompleted(), + goal.getComments().stream() + .map(comment -> new GoalCommentResponseDto( + comment.getCommentId(), + comment.getUser().getNickname(), + comment.getContent(), + comment.getCreatedAt(), + comment.getEmoji() + )) + .collect(Collectors.toList()) + )) + .collect(Collectors.toList()); + } + + // Goal ID를 기준으로 목표 상세 조회 (댓글 포함) @Transactional public Optional getGoalDetailsWithComments(Long goalId) {