File tree Expand file tree Collapse file tree 4 files changed +95
-0
lines changed
src/main/kotlin/nexters/weski/app_version Expand file tree Collapse file tree 4 files changed +95
-0
lines changed Original file line number Diff line number Diff line change 1+ package nexters.weski.app_version
2+
3+ import io.swagger.v3.oas.annotations.Operation
4+ import io.swagger.v3.oas.annotations.Parameter
5+ import io.swagger.v3.oas.annotations.tags.Tag
6+ import org.springframework.web.bind.annotation.*
7+
8+ @Tag(name = " App 최소 버전 check API" , description = " App 최소 버전 check API" )
9+ @RestController
10+ class AppVersionCheckController (
11+ private val appVersionCheckService : AppVersionCheckService ,
12+ ) {
13+ @Operation(summary = " App 버전 조회 API" )
14+ @GetMapping(" /api/app-version" )
15+ fun getAppVersion (
16+ @Parameter(description = " 사용자 App platform" , example = " iOS" )
17+ @RequestParam platform : String ,
18+ @Parameter(description = " 사용자 현재 App version" , example = " 1.0.0" )
19+ @RequestParam version : String ,
20+ ): AppVersionResponseDto {
21+ if (platform.uppercase() !in Platform .entries.map { it.name }) {
22+ throw IllegalArgumentException (" platform must be one of ${Platform .entries.joinToString()} " )
23+ }
24+ return appVersionCheckService.getAppVersion(
25+ platform = Platform .valueOf(platform.uppercase()),
26+ version = version,
27+ )
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ package nexters.weski.app_version
2+
3+ import org.springframework.stereotype.Service
4+
5+ @Service
6+ class AppVersionCheckService {
7+ companion object {
8+ const val IOS_MIN_VERSION = " 3.0.1"
9+ const val ANDROID_MIN_VERSION = " 3.0.1"
10+ }
11+ fun getAppVersion (
12+ platform : Platform ,
13+ version : String ,
14+ ): AppVersionResponseDto {
15+ val minVersion = when (platform) {
16+ Platform .IOS -> IOS_MIN_VERSION
17+ Platform .ANDROID -> ANDROID_MIN_VERSION
18+ else -> throw IllegalArgumentException (" Unsupported platform: $platform " )
19+ }
20+ return AppVersionResponseDto (
21+ platform = platform,
22+ minVersion = minVersion,
23+ isForceUpdate = isForceUpdate(platform, version),
24+ )
25+ }
26+
27+ private fun isForceUpdate (
28+ platform : Platform ,
29+ version : String ,
30+ ): Boolean {
31+ return when (platform) {
32+ Platform .IOS -> isForceUpdateForIOS(version)
33+ Platform .ANDROID -> isForceUpdateForAndroid(version)
34+ else -> throw IllegalArgumentException (" Unsupported platform: $platform " )
35+ }
36+ }
37+
38+ private fun isForceUpdateForIOS (version : String ): Boolean {
39+ return version < IOS_MIN_VERSION
40+ }
41+
42+ private fun isForceUpdateForAndroid (version : String ): Boolean {
43+ return version < ANDROID_MIN_VERSION
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ package nexters.weski.app_version
2+
3+ import io.swagger.v3.oas.annotations.media.Schema
4+
5+ @Schema(description = " App 최소 버전, 강제업데이트 flag 데이터" )
6+ data class AppVersionResponseDto (
7+ // 예: "android", "ios" 등
8+ val platform : Platform ,
9+ // 클라이언트에서 동작 가능한 최소 버전
10+ val minVersion : String ,
11+ // true = App 강제 업데이트 대상임을 의미
12+ val isForceUpdate : Boolean = false ,
13+ )
Original file line number Diff line number Diff line change 1+ package nexters.weski.app_version
2+
3+ enum class Platform {
4+ IOS ,
5+ ANDROID ,
6+ WEB ,
7+ UNKNOWN ,
8+ }
You can’t perform that action at this time.
0 commit comments