Skip to content

Commit

Permalink
Merge pull request #150 from MADA-UMC/develop
Browse files Browse the repository at this point in the history
feat: comment가 없을 경우 반환값 수정
  • Loading branch information
Jeonghee-Han authored Oct 17, 2024
2 parents f80cc5a + 875f4fc commit e60aa1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ public ResponseEntity<Map<String, Object>> getUserTimetableComment(Authenticatio
Optional<User> userOptional = userRepository.findByAuthId(authentication.getName());
User user = userOptional.get();
CommentResponseDto userComment = timetableService.getUserComment(user, date);
Map<String, Object> data = new LinkedHashMap<>();
data.put("Comment", userComment);
Map<String, Object> result = new LinkedHashMap<>();
result.put("data", data);

if (userComment != null) {
Map<String, Object> data = new LinkedHashMap<>();
data.put("Comment", userComment);
result.put("data", data); // comment가 있으면 data를 추가
} else {
result.put("data", null); // comment가 없으면 data를 null로 설정
}

return ResponseEntity.ok().body(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,9 @@ public CommentResponseDto updateComment (User user, LocalDate date, CommentReque
// 특정 유저 comment 조회 로직
public CommentResponseDto getUserComment(User user, LocalDate date) {
validateUserId(user);

Comment comment = commentRepository.findCommentByUserIdAndDateIs(user, date)
.orElseThrow(() -> new IllegalArgumentException("NOT_FOUND_ERROR"));

.orElse(null);
if (comment == null) {return null;}
return new CommentResponseDto(comment.getId(), comment.getDate(), comment.getContent());
}

Expand Down

0 comments on commit e60aa1e

Please sign in to comment.