From 91b2837e1e7388c03279a3908405b6bd8c337eb5 Mon Sep 17 00:00:00 2001 From: pparkjs Date: Sun, 4 Feb 2024 19:55:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20=20s3=20=EB=B2=84=ED=82=B7=20end?= =?UTF-8?q?point=20CloudFront=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20profile=20dev=20or=20local=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=EB=A1=9C=20=EB=8F=99=EC=A0=81=20=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/SpringEnvironmentUtil.java | 30 +++++++++++++++++++ .../constants/EnvironmentConstants.java | 15 ++++++++++ .../common/constants/UrlConstants.java | 2 +- .../application/service/ImageService.java | 15 ++++------ .../custom/impl/UserRepositoryImpl.java | 4 +-- 5 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java create mode 100644 src/main/java/com/listywave/common/constants/EnvironmentConstants.java diff --git a/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java b/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java new file mode 100644 index 00000000..8c1feeac --- /dev/null +++ b/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java @@ -0,0 +1,30 @@ +package com.listywave.common.config; + +import com.listywave.common.constants.EnvironmentConstants; +import java.util.Arrays; +import java.util.stream.Stream; +import lombok.RequiredArgsConstructor; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class SpringEnvironmentUtil { + + private final Environment environment; + + public String getCurrentProfile() { + return getActiveProfile() + .filter( + profile -> + profile.equals(EnvironmentConstants.LOCAL.getValue()) + || profile.equals(EnvironmentConstants.DEV.getValue()) + ) + .findFirst() + .orElse(EnvironmentConstants.LOCAL.getValue()); + } + + public Stream getActiveProfile() { + return Arrays.stream(environment.getActiveProfiles()); + } +} diff --git a/src/main/java/com/listywave/common/constants/EnvironmentConstants.java b/src/main/java/com/listywave/common/constants/EnvironmentConstants.java new file mode 100644 index 00000000..93e67289 --- /dev/null +++ b/src/main/java/com/listywave/common/constants/EnvironmentConstants.java @@ -0,0 +1,15 @@ +package com.listywave.common.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum EnvironmentConstants { + + LOCAL("local"), + DEV("dev"), + ; + + private final String value; +} diff --git a/src/main/java/com/listywave/common/constants/UrlConstants.java b/src/main/java/com/listywave/common/constants/UrlConstants.java index 67c28b46..2c4bb57b 100644 --- a/src/main/java/com/listywave/common/constants/UrlConstants.java +++ b/src/main/java/com/listywave/common/constants/UrlConstants.java @@ -7,7 +7,7 @@ @AllArgsConstructor public enum UrlConstants { - IMAGE_DOMAIN_URL("https://image.listy-wave.today"), + IMAGE_DOMAIN_URL("https://image.listywave.com"), ; private String value; diff --git a/src/main/java/com/listywave/image/application/service/ImageService.java b/src/main/java/com/listywave/image/application/service/ImageService.java index d5ccb30b..fabe6a3a 100644 --- a/src/main/java/com/listywave/image/application/service/ImageService.java +++ b/src/main/java/com/listywave/image/application/service/ImageService.java @@ -5,6 +5,8 @@ import com.amazonaws.services.s3.Headers; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; +import com.listywave.common.config.SpringEnvironmentUtil; +import com.listywave.common.constants.UrlConstants; import com.listywave.common.exception.CustomException; import com.listywave.common.exception.ErrorCode; import com.listywave.common.util.UserUtil; @@ -32,9 +34,7 @@ public class ImageService { @Value("${cloud.s3.bucket}") private String bucket; - //TODO: endPoint는 cloudFron 적용하면 지우기 - @Value("${cloud.s3.endpoint}") - private String endPoint; + private final SpringEnvironmentUtil springEnvironmentUtil; private final AmazonS3 amazonS3; private final UserUtil userUtil; private final ItemRepository itemRepository; @@ -93,7 +93,6 @@ public void uploadCompleteItemImages(Long ownerId, Long listId, List findFeedLists(Long userId, String type, CategoryType category userIdEq(userId), typeEq(type), categoryEq(category), - listIdGt(cursorId) + listIdLt(cursorId) ) .distinct() .limit(size + 1) @@ -35,7 +35,7 @@ public List findFeedLists(Long userId, String type, CategoryType category return fetch; } - private BooleanExpression listIdGt(Long cursorId) { + private BooleanExpression listIdLt(Long cursorId) { return cursorId == null ? null : lists.id.lt(cursorId); } From e216d660cb0a6c3e0133ad44e9acd6882b79f3f3 Mon Sep 17 00:00:00 2001 From: pparkjs Date: Mon, 5 Feb 2024 22:04:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=20refactor:=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20URL=EA=B3=BC=20=ED=94=84=EB=A1=9C=ED=95=84=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=95=9C=EC=88=98=20ImageService=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/SpringEnvironmentUtil.java | 30 ------------------- .../common/constants/UrlConstants.java | 14 --------- .../application/service/ImageService.java | 27 +++++++++++++---- 3 files changed, 21 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java delete mode 100644 src/main/java/com/listywave/common/constants/UrlConstants.java diff --git a/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java b/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java deleted file mode 100644 index 8c1feeac..00000000 --- a/src/main/java/com/listywave/common/config/SpringEnvironmentUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.listywave.common.config; - -import com.listywave.common.constants.EnvironmentConstants; -import java.util.Arrays; -import java.util.stream.Stream; -import lombok.RequiredArgsConstructor; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class SpringEnvironmentUtil { - - private final Environment environment; - - public String getCurrentProfile() { - return getActiveProfile() - .filter( - profile -> - profile.equals(EnvironmentConstants.LOCAL.getValue()) - || profile.equals(EnvironmentConstants.DEV.getValue()) - ) - .findFirst() - .orElse(EnvironmentConstants.LOCAL.getValue()); - } - - public Stream getActiveProfile() { - return Arrays.stream(environment.getActiveProfiles()); - } -} diff --git a/src/main/java/com/listywave/common/constants/UrlConstants.java b/src/main/java/com/listywave/common/constants/UrlConstants.java deleted file mode 100644 index 2c4bb57b..00000000 --- a/src/main/java/com/listywave/common/constants/UrlConstants.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.listywave.common.constants; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum UrlConstants { - - IMAGE_DOMAIN_URL("https://image.listywave.com"), - ; - - private String value; -} diff --git a/src/main/java/com/listywave/image/application/service/ImageService.java b/src/main/java/com/listywave/image/application/service/ImageService.java index fabe6a3a..c8670998 100644 --- a/src/main/java/com/listywave/image/application/service/ImageService.java +++ b/src/main/java/com/listywave/image/application/service/ImageService.java @@ -5,8 +5,6 @@ import com.amazonaws.services.s3.Headers; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; -import com.listywave.common.config.SpringEnvironmentUtil; -import com.listywave.common.constants.UrlConstants; import com.listywave.common.exception.CustomException; import com.listywave.common.exception.ErrorCode; import com.listywave.common.util.UserUtil; @@ -19,11 +17,13 @@ import com.listywave.list.repository.ItemRepository; import com.listywave.list.repository.ListRepository; import com.listywave.user.application.domain.User; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,9 +32,13 @@ @RequiredArgsConstructor public class ImageService { + private static final String IMAGE_DOMAIN_URL = "https://image.listywave.com"; + private static final String LOCAL = "local"; + private static final String DEV = "dev"; + @Value("${cloud.s3.bucket}") private String bucket; - private final SpringEnvironmentUtil springEnvironmentUtil; + private final Environment environment; private final AmazonS3 amazonS3; private final UserUtil userUtil; private final ItemRepository itemRepository; @@ -101,9 +105,9 @@ private String createReadImageUrl( String imageKey, ImageFileExtension imageFileExtension ) { - return UrlConstants.IMAGE_DOMAIN_URL.getValue() + return IMAGE_DOMAIN_URL + "/" - + springEnvironmentUtil.getCurrentProfile() + + getCurrentProfile() + "/" + imageType.getValue() + "/" @@ -120,7 +124,7 @@ private String createFileName( String imageKey, ImageFileExtension imageFileExtension ) { - return springEnvironmentUtil.getCurrentProfile() + return getCurrentProfile() + "/" + imageType.getValue() + "/" @@ -180,4 +184,15 @@ private Lists findListById(Long listId) { .findById(listId) .orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND, "존재하지 않는 리스트입니다.")); } + + public String getCurrentProfile() { + return Arrays.stream(environment.getActiveProfiles()) + .filter(this::isActivateDev) + .findFirst() + .orElse(LOCAL); + } + + private boolean isActivateDev(String profile) { + return profile.equals(DEV); + } }