Skip to content

Commit

Permalink
refactor: DB 조회 방법 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
wonyangs committed Oct 17, 2024
1 parent c64fef9 commit 388fc1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.first.flash.version.application;

import com.first.flash.version.domain.AppVersion;
import java.util.NoSuchElementException;
import com.first.flash.version.infrastructure.VersionJpaRepository;
import com.first.flash.version.application.dto.VersionResponseDto;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,7 +15,8 @@ public class VersionService {
private final VersionJpaRepository versionJpaRepository;

public VersionResponseDto getLatestVersions() {
AppVersion version = versionJpaRepository.findAll().get(0);
return new VersionResponseDto(version.getAndroid(), version.getIos());
return versionJpaRepository.findTopByOrderByIdDesc()
.map(version -> new VersionResponseDto(version.getAndroid(), version.getIos()))
.orElseThrow(() -> new NoSuchElementException("No version information available"));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.first.flash.version.infrastructure;

import com.first.flash.version.domain.AppVersion;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;

public interface VersionJpaRepository extends JpaRepository<AppVersion, Long> {

List<AppVersion> findAll();
Optional<AppVersion> findTopByOrderByIdDesc();
}

0 comments on commit 388fc1a

Please sign in to comment.