-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: ProfileCheckController 구현 * config: Spring Actuator 의존성 추가 * config: submodule 변경 저장 --------- Co-authored-by: Eunsol Kim <[email protected]>
- Loading branch information
1 parent
a23c073
commit 280182e
Showing
4 changed files
with
68 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
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/shook/shook/status/ProfileCheckController.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,22 @@ | ||
package shook.shook.status; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.env.Environment; | ||
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; | ||
import shook.shook.status.response.ProfileResponse; | ||
|
||
@RestController | ||
@RequestMapping("/status/profile") | ||
@RequiredArgsConstructor | ||
public class ProfileCheckController { | ||
|
||
private final Environment environment; | ||
|
||
@GetMapping | ||
public ResponseEntity<ProfileResponse> getProfile() { | ||
return ResponseEntity.ok(new ProfileResponse(environment.getActiveProfiles())); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/shook/shook/status/response/ProfileResponse.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,23 @@ | ||
package shook.shook.status.response; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ProfileResponse { | ||
|
||
private final String profile; | ||
|
||
public ProfileResponse(final String[] profiles) { | ||
this.profile = findReservedProfile(profiles); | ||
} | ||
|
||
private String findReservedProfile(final String[] profiles) { | ||
return Arrays.stream(profiles) | ||
.filter(ReservedProfiles::isExist) | ||
.findFirst() | ||
.orElse(profiles[0]); | ||
} | ||
|
||
public String getProfiles() { | ||
return profile; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/shook/shook/status/response/ReservedProfiles.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,20 @@ | ||
package shook.shook.status.response; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
public enum ReservedProfiles { | ||
PROD1, | ||
PROD2, | ||
DEV, | ||
LOCAL, | ||
TEST; | ||
|
||
public static boolean isExist(final String target) { | ||
final Optional<String> findProfile = Arrays.stream(values()) | ||
.map(ReservedProfiles::name) | ||
.filter(valueName -> valueName.equals(target.toUpperCase())) | ||
.findAny(); | ||
return findProfile.isPresent(); | ||
} | ||
} |