From 754c3474dcc211d18f886f4109412a0c746bfd8c Mon Sep 17 00:00:00 2001 From: suhyunsim Date: Tue, 29 Dec 2020 14:58:28 +0900 Subject: [PATCH] feat: Add GetMapping profile to ProfileController - Get all the active profiles and check if there's a profile for deploy. Issue #38 --- .../profile/controller/ProfileController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/poogle/phog/web/profile/controller/ProfileController.java diff --git a/src/main/java/com/poogle/phog/web/profile/controller/ProfileController.java b/src/main/java/com/poogle/phog/web/profile/controller/ProfileController.java new file mode 100644 index 0000000..43308a3 --- /dev/null +++ b/src/main/java/com/poogle/phog/web/profile/controller/ProfileController.java @@ -0,0 +1,26 @@ +package com.poogle.phog.web.profile.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; + +@RequiredArgsConstructor +@RestController +public class ProfileController { + private final Environment env; + + @GetMapping("/profile") + public String profile() { + List profiles = Arrays.asList(env.getActiveProfiles()); + List deployProfiles = Arrays.asList("deploy", "deploy1", "deploy2"); + String defaultProfile = profiles.isEmpty() ? "default" : profiles.get(0); + return profiles.stream() + .filter(deployProfiles::contains) + .findAny() + .orElse(defaultProfile); + } +}