From 280182e4703f2748f1167092e65f3dfd3d674aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8A=A4=ED=94=8C=EB=A6=BF?= Date: Thu, 19 Oct 2023 11:58:42 +0900 Subject: [PATCH] =?UTF-8?q?Feat/#514=20=EB=AC=B4=EC=A4=91=EB=8B=A8=20?= =?UTF-8?q?=EB=B0=B0=ED=8F=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20Actuator=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20Profile=20API=20=EC=83=9D=EC=84=B1=20(#52?= =?UTF-8?q?1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ProfileCheckController 구현 * config: Spring Actuator 의존성 추가 * config: submodule 변경 저장 --------- Co-authored-by: Eunsol Kim <61370551+Cyma-s@users.noreply.github.com> --- backend/build.gradle | 3 +++ .../shook/status/ProfileCheckController.java | 22 ++++++++++++++++++ .../status/response/ProfileResponse.java | 23 +++++++++++++++++++ .../status/response/ReservedProfiles.java | 20 ++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 backend/src/main/java/shook/shook/status/ProfileCheckController.java create mode 100644 backend/src/main/java/shook/shook/status/response/ProfileResponse.java create mode 100644 backend/src/main/java/shook/shook/status/response/ReservedProfiles.java diff --git a/backend/build.gradle b/backend/build.gradle index b4b83601a..4c2c1f1ea 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -51,6 +51,9 @@ dependencies { //xlsx reader implementation group: 'org.apache.poi', name: 'poi', version: '5.0.0' implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.0.0' + + //actuator + implementation 'org.springframework.boot:spring-boot-starter-actuator' } tasks.named('test') { diff --git a/backend/src/main/java/shook/shook/status/ProfileCheckController.java b/backend/src/main/java/shook/shook/status/ProfileCheckController.java new file mode 100644 index 000000000..170a0d27d --- /dev/null +++ b/backend/src/main/java/shook/shook/status/ProfileCheckController.java @@ -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 getProfile() { + return ResponseEntity.ok(new ProfileResponse(environment.getActiveProfiles())); + } +} diff --git a/backend/src/main/java/shook/shook/status/response/ProfileResponse.java b/backend/src/main/java/shook/shook/status/response/ProfileResponse.java new file mode 100644 index 000000000..696e2a060 --- /dev/null +++ b/backend/src/main/java/shook/shook/status/response/ProfileResponse.java @@ -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; + } +} diff --git a/backend/src/main/java/shook/shook/status/response/ReservedProfiles.java b/backend/src/main/java/shook/shook/status/response/ReservedProfiles.java new file mode 100644 index 000000000..45cfc712d --- /dev/null +++ b/backend/src/main/java/shook/shook/status/response/ReservedProfiles.java @@ -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 findProfile = Arrays.stream(values()) + .map(ReservedProfiles::name) + .filter(valueName -> valueName.equals(target.toUpperCase())) + .findAny(); + return findProfile.isPresent(); + } +}