From c64fef9428022a58a10e41ba16eb706c162d9e6e Mon Sep 17 00:00:00 2001 From: wonyangs Date: Thu, 17 Oct 2024 13:50:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=95=B1=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flash/global/config/SecurityConfig.java | 3 +- .../version/application/VersionService.java | 21 +++++++++++ .../application/dto/VersionResponseDto.java | 4 +++ .../flash/version/domain/AppVersion.java | 24 +++++++++++++ .../infrastructure/VersionJpaRepository.java | 10 ++++++ .../flash/version/ui/VersionController.java | 36 +++++++++++++++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/first/flash/version/application/VersionService.java create mode 100644 src/main/java/com/first/flash/version/application/dto/VersionResponseDto.java create mode 100644 src/main/java/com/first/flash/version/domain/AppVersion.java create mode 100644 src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java create mode 100644 src/main/java/com/first/flash/version/ui/VersionController.java diff --git a/src/main/java/com/first/flash/global/config/SecurityConfig.java b/src/main/java/com/first/flash/global/config/SecurityConfig.java index 4f5880cf..09a329fe 100644 --- a/src/main/java/com/first/flash/global/config/SecurityConfig.java +++ b/src/main/java/com/first/flash/global/config/SecurityConfig.java @@ -32,7 +32,8 @@ public class SecurityConfig { "/auth/login", "/swagger-ui/*", "/v1/api-docs/**", - "/flash-climbing-answer-health/**" + "/flash-climbing-answer-health/**", + "/versions" }; private static final String COMPLETE_REGISTRATION = "/members"; private static final String MARKETING_CONSENT = "/members/marketing-consent"; diff --git a/src/main/java/com/first/flash/version/application/VersionService.java b/src/main/java/com/first/flash/version/application/VersionService.java new file mode 100644 index 00000000..d7015932 --- /dev/null +++ b/src/main/java/com/first/flash/version/application/VersionService.java @@ -0,0 +1,21 @@ +package com.first.flash.version.application; + +import com.first.flash.version.domain.AppVersion; +import com.first.flash.version.infrastructure.VersionJpaRepository; +import com.first.flash.version.application.dto.VersionResponseDto; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class VersionService { + + private final VersionJpaRepository versionJpaRepository; + + public VersionResponseDto getLatestVersions() { + AppVersion version = versionJpaRepository.findAll().get(0); + return new VersionResponseDto(version.getAndroid(), version.getIos()); + } +} \ No newline at end of file diff --git a/src/main/java/com/first/flash/version/application/dto/VersionResponseDto.java b/src/main/java/com/first/flash/version/application/dto/VersionResponseDto.java new file mode 100644 index 00000000..bcfbba5f --- /dev/null +++ b/src/main/java/com/first/flash/version/application/dto/VersionResponseDto.java @@ -0,0 +1,4 @@ +package com.first.flash.version.application.dto; + +public record VersionResponseDto(String android, String ios) { +} \ No newline at end of file diff --git a/src/main/java/com/first/flash/version/domain/AppVersion.java b/src/main/java/com/first/flash/version/domain/AppVersion.java new file mode 100644 index 00000000..acff2535 --- /dev/null +++ b/src/main/java/com/first/flash/version/domain/AppVersion.java @@ -0,0 +1,24 @@ +package com.first.flash.version.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Getter +@ToString +public class AppVersion { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String android; + private String ios; + +} diff --git a/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java b/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java new file mode 100644 index 00000000..fffd112e --- /dev/null +++ b/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java @@ -0,0 +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; + +public interface VersionJpaRepository extends JpaRepository { + + List findAll(); +} \ No newline at end of file diff --git a/src/main/java/com/first/flash/version/ui/VersionController.java b/src/main/java/com/first/flash/version/ui/VersionController.java new file mode 100644 index 00000000..4a997a8e --- /dev/null +++ b/src/main/java/com/first/flash/version/ui/VersionController.java @@ -0,0 +1,36 @@ +package com.first.flash.version.ui; + +import com.first.flash.climbing.solution.application.dto.SolutionsPageResponseDto; +import com.first.flash.version.application.VersionService; +import com.first.flash.version.application.dto.VersionResponseDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "versions", description = "앱 버전 정보 API") +@RestController +@RequestMapping +@RequiredArgsConstructor +public class VersionController { + + private final VersionService versionService; + + @Operation(summary = "버전 정보 조회", description = "앱 최신 버전 정보 조회") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "성공적으로 조회함", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = VersionResponseDto.class))) + }) + @GetMapping("versions") + public ResponseEntity getLatestVersions() { + VersionResponseDto versionInfo = versionService.getLatestVersions(); + return ResponseEntity.ok(versionInfo); + } +} \ No newline at end of file From 388fc1a043aa0855b05ebdae44f1f48bd0021a91 Mon Sep 17 00:00:00 2001 From: wonyangs Date: Thu, 17 Oct 2024 14:11:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20DB=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B0=A9=EB=B2=95=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../first/flash/version/application/VersionService.java | 7 ++++--- .../flash/version/infrastructure/VersionJpaRepository.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/first/flash/version/application/VersionService.java b/src/main/java/com/first/flash/version/application/VersionService.java index d7015932..270b332d 100644 --- a/src/main/java/com/first/flash/version/application/VersionService.java +++ b/src/main/java/com/first/flash/version/application/VersionService.java @@ -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; @@ -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")); } } \ No newline at end of file diff --git a/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java b/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java index fffd112e..94ff9efa 100644 --- a/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java +++ b/src/main/java/com/first/flash/version/infrastructure/VersionJpaRepository.java @@ -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 { - List findAll(); + Optional findTopByOrderByIdDesc(); } \ No newline at end of file