Skip to content

Commit

Permalink
Merge pull request #149 from MADA-UMC/server-heerang
Browse files Browse the repository at this point in the history
feat: comment가 없을 경우 반환값 수정
  • Loading branch information
Jeonghee-Han authored Oct 17, 2024
2 parents 5df8f47 + 07d5adc commit 875f4fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 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
2 changes: 1 addition & 1 deletion src/main/java/com/umc/mada/timetable/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Comment {
@Column(name = "date", nullable = false)
private LocalDate date;

@Column(name = "content")
@Column(name = "content", nullable = false)
private String content;

@CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TimetableService(UserRepository userRepository, TimetableRepository timet
this.calendarRepository = calendarRepository;
this.repeatTodoRepository = repeatTodoRepository;
}

@Transactional
// 시간표 일정 생성 로직
public TimetableResponseDto createTimetable(User user, TimetableRequestDto timetableRequestDto){
// 유효성 검사 메서드를 호출하여 해당 ID가 데이터베이스에 존재하는지 확인
Expand Down Expand Up @@ -211,7 +211,7 @@ public List<TimetableResponseDto> getWeeklyTimetable(User userId) {
// checkAndLoadDailyData(user, today);
// }
// }

@Transactional
// 주간 시간표의 일정을 기반으로 한 일일 시간표 생성 메서드
public Map<String, Object> checkAndLoadDailyData(User user, LocalDate date) {
java.time.DayOfWeek dayOfWeek = date.getDayOfWeek();
Expand Down Expand Up @@ -261,7 +261,7 @@ public Map<String, Object> checkAndLoadDailyData(User user, LocalDate date) {
result.put("data",data);
return result;
}

@Transactional
// comment 생성 로직
public CommentResponseDto createComment(User user, CommentRequestDto commentRequestDto){
validateUserId(user);
Expand Down 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 875f4fc

Please sign in to comment.