-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from YAPP-Github/feature/DRAW-192
DRAW-192 강제 업데이트
- Loading branch information
Showing
10 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
app/api/src/main/kotlin/com/xorker/draw/HealthCheckController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
package com.xorker.draw | ||
|
||
import com.xorker.draw.support.logging.logger | ||
import com.xorker.draw.version.ApiMinVersion | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.slf4j.MDC | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "개발용 API") | ||
@RestController | ||
class HealthCheckController { | ||
val log = logger() | ||
|
||
@Operation(hidden = true) | ||
@GetMapping("/ping") | ||
fun ping(): String { | ||
return "pong" | ||
} | ||
|
||
@Operation(hidden = true) | ||
@GetMapping("/test") | ||
fun test(): String { | ||
MDC.put("test", "test") | ||
log.info("Call Test") | ||
return "pong" | ||
} | ||
|
||
@Operation(summary = "강업 테스트") | ||
@ApiMinVersion(androidVersion = "99.99.99", iosVersion = "99.99.99") | ||
@GetMapping("/force-update") | ||
fun forceUpdate() {} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/api/src/main/kotlin/com/xorker/draw/version/ApiMinVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.xorker.draw.version | ||
|
||
@Target(allowedTargets = [AnnotationTarget.FUNCTION]) | ||
annotation class ApiMinVersion( | ||
val androidVersion: String = "0.0.0", | ||
val iosVersion: String = "0.0.0", | ||
) |
53 changes: 53 additions & 0 deletions
53
app/api/src/main/kotlin/com/xorker/draw/version/ForceUpdateAspect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.xorker.draw.version | ||
|
||
import com.xorker.draw.exception.NeedForceUpdateException | ||
import org.aspectj.lang.ProceedingJoinPoint | ||
import org.aspectj.lang.annotation.Around | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.aspectj.lang.reflect.MethodSignature | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.context.request.RequestContextHolder | ||
import org.springframework.web.context.request.ServletRequestAttributes | ||
|
||
@Aspect | ||
@Component | ||
class ForceUpdateAspect { | ||
|
||
@Around("@annotation(ApiMinVersion)") | ||
fun checkForceUpdate(joinPoint: ProceedingJoinPoint): Any { | ||
try { | ||
val attributes = RequestContextHolder.currentRequestAttributes() as ServletRequestAttributes | ||
val userAgent = attributes.request.getHeader("User-Agent") | ||
|
||
val (appType, version) = userAgent.getVersionInfo() | ||
|
||
val signature = joinPoint.signature as MethodSignature | ||
val method = signature.method | ||
val annotation = method.getAnnotation(ApiMinVersion::class.java) | ||
|
||
if (appType.lowercase() == "android") { | ||
if (Version.of(annotation.androidVersion) > version) { | ||
throw NeedForceUpdateException | ||
} | ||
} else if (appType.lowercase() == "ios") { | ||
if (Version.of(annotation.iosVersion) > version) { | ||
throw NeedForceUpdateException | ||
} | ||
} | ||
} catch (e: Exception) { | ||
throw NeedForceUpdateException | ||
} | ||
|
||
return joinPoint.proceed() | ||
} | ||
|
||
private fun String.getVersionInfo(): Pair<String, Version> { | ||
val lastIndexSpace = if (this.lastIndexOf(' ') == -1) 0 else this.lastIndexOf(' ') | ||
val lastIndexSlash = this.lastIndexOf('/') | ||
|
||
val appType = this.substring(lastIndexSpace, lastIndexSlash) | ||
val version = this.substring(lastIndexSlash + 1) | ||
|
||
return Pair(appType, Version.of(version)) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/api/src/main/kotlin/com/xorker/draw/version/Version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.xorker.draw.version | ||
|
||
class Version( | ||
val major: Int, | ||
val minor: Int, | ||
val patch: Int, | ||
) : Comparable<Version> { | ||
override fun compareTo(other: Version): Int { | ||
if (major > other.major) return 1 | ||
if (major < other.major) return -1 | ||
|
||
if (minor > other.minor) return 1 | ||
if (minor < other.minor) return -1 | ||
|
||
return patch.compareTo(patch) | ||
} | ||
|
||
companion object { | ||
fun of(version: String): Version { | ||
val split = version.split(".") | ||
return Version(split[0].toInt(), split[1].toInt(), split.getOrElse(2) { "0" }.toInt()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters