Skip to content

Commit

Permalink
Merge pull request #43 from CSID-DGU/develop
Browse files Browse the repository at this point in the history
โœ๏ธ [Fix]: ํ”ผ๋“œ ๋ฐ˜ํ™˜๊ฐ’ ์ˆ˜์ •
  • Loading branch information
saokiritoni authored Dec 3, 2024
2 parents 1bd9fc2 + a35b704 commit 8959d1b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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

0 comments on commit 8959d1b

Please sign in to comment.