Skip to content

Commit

Permalink
내 재활 운동 기록 조회 API에서 startDate 이전의 데이터가 없을 때 발생하는 404 오류 수정 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee committed Jul 27, 2024
1 parent abc336f commit 5d2b997
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface RecordJpaRepository extends JpaRepository<RecordEntity, Long> {

Expand All @@ -24,7 +25,7 @@ List<RecordEntity> findByDateBetween(
"WHERE r.createdAt < :startDateTime " +
"ORDER BY r.createdAt DESC " +
"LIMIT 1")
RecordEntity findLatestBeforeStartDate(
Optional<RecordEntity> findLatestBeforeStartDate(
@Param("startDateTime") LocalDateTime startDateTime
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Repository
@RequiredArgsConstructor
Expand All @@ -34,7 +35,8 @@ public List<Record> findByDateBetween(LocalDateTime startDateTime, LocalDateTime

@Override
public Record findLatestBeforeStartDate(LocalDateTime startDateTime) {
RecordEntity jpaEntity = repository.findLatestBeforeStartDate(startDateTime);
return mapper.toDomain(jpaEntity);
Optional<RecordEntity> jpaEntity = repository.findLatestBeforeStartDate(startDateTime);
return jpaEntity.map(mapper::toDomain)
.orElse(null);
}
}

0 comments on commit 5d2b997

Please sign in to comment.