Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✏️ [Fix]: 피드 반환값 수정 #43

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ public class FeedController {
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자")
})
@GetMapping
public ResponseEntity<List<FeedGoalDto>> getTodayFeedGoals(HttpSession session) {
public ResponseEntity<List<GoalDetailResponseDto>> getTodayFeedGoals(HttpSession session) {
Long userId = (Long) session.getAttribute("userId");
if (userId == null) {
return ResponseEntity.status(401).build();
}
List<FeedGoalDto> feedGoals = goalService.getTodayFeedGoals(userId);
List<GoalDetailResponseDto> feedGoals = goalService.getTodayFeedGoalsAsDetails(userId);
return ResponseEntity.ok(feedGoals);
}


@Operation(summary = "단일 목표 상세 조회", description = "단일 목표와 그에 달린 모든 댓글을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "목표 상세 조회 성공"),
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/dongguk/osori/domain/goal/service/GoalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ public List<FeedGoalDto> getTodayFeedGoals(Long userId) {
.collect(Collectors.toList());
}


@Transactional
public List<GoalDetailResponseDto> getTodayFeedGoalsAsDetails(Long userId) {
User loggedInUser = getLoggedInUser(userId); // 로그인된 사용자 가져오기
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
LocalDateTime endOfDay = startOfDay.plusDays(1);

List<User> 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<GoalDetailResponseDto> getGoalDetailsWithComments(Long goalId) {
Expand Down
Loading