-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
0 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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/moneymong/global/version/VersionController.java
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,45 @@ | ||
package com.moneymong.global.version; | ||
|
||
import com.moneymong.global.exception.enums.ErrorCode; | ||
import com.moneymong.global.version.dto.VersionRequest; | ||
import com.moneymong.global.version.exception.VersionTooLowException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/version") | ||
public class VersionController { | ||
|
||
@Value("${app.minimum.version}") | ||
private String minimumAppVersion; | ||
|
||
@PostMapping | ||
public String checkVersion(@RequestBody VersionRequest request) { | ||
if (isVersionLower(request.getVersion(), minimumAppVersion)) { | ||
throw new VersionTooLowException(ErrorCode.VERSION_TOO_LOW); | ||
} | ||
|
||
return "Version is up to date."; | ||
} | ||
|
||
private boolean isVersionLower(String currentVersion, String minimumVersion) { | ||
String[] currentParts = currentVersion.split("\\."); | ||
String[] minimumParts = minimumVersion.split("\\."); | ||
|
||
int length = Math.max(currentParts.length, minimumParts.length); | ||
for (int i = 0; i < length; i++) { | ||
int currentPart = i < currentParts.length ? Integer.parseInt(currentParts[i]) : 0; | ||
int minimumPart = i < minimumParts.length ? Integer.parseInt(minimumParts[i]) : 0; | ||
|
||
if (currentPart < minimumPart) { | ||
return true; | ||
} else if (currentPart > minimumPart) { | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/moneymong/global/version/dto/VersionRequest.java
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,8 @@ | ||
package com.moneymong.global.version.dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class VersionRequest { | ||
private String version; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/moneymong/global/version/exception/VersionTooLowException.java
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,14 @@ | ||
package com.moneymong.global.version.exception; | ||
|
||
import com.moneymong.global.exception.custom.BusinessException; | ||
import com.moneymong.global.exception.enums.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public class VersionTooLowException extends BusinessException { | ||
|
||
public VersionTooLowException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -70,3 +70,7 @@ decorator: | |
agency: | ||
invitation-code: | ||
key: ${INVITATION_CODE_KEY} | ||
|
||
app: | ||
minimum: | ||
version: ${APP_MINIMUM_VERSION} |