From 1bf4674e23f032a098c83b71c840d4e35cb815cb Mon Sep 17 00:00:00 2001 From: SeHwan Bong Date: Wed, 27 Dec 2023 23:39:33 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=EC=9C=A0=EC=A0=80=20=EC=B7=A8?= =?UTF-8?q?=ED=96=A5=20=EB=8B=B5=EB=B3=80=20=EC=A4=91=EB=B6=84=EB=A5=98=20?= =?UTF-8?q?=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20API=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 유저 취향 답변 중분류 별 조회 API 필드 변경 & 로직 리팩토링 * edit : 애플 로그인 키 로직 변경 --- .../api/user/service/UserFavorUseCase.java | 32 +++++++++++-------- .../server/core/jwt/JwtTokenProvider.java | 15 +-------- .../core/properties/OauthProperties.java | 5 +++ Core/src/main/resources/application-core.yml | 1 + .../domains/user/domain/DetailCategory.java | 7 ++++ .../domain/domains/user/vo/UserAnswerVo.java | 7 +++- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/Api/src/main/java/tify/server/api/user/service/UserFavorUseCase.java b/Api/src/main/java/tify/server/api/user/service/UserFavorUseCase.java index 8e7017fb..ba29ad37 100644 --- a/Api/src/main/java/tify/server/api/user/service/UserFavorUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/UserFavorUseCase.java @@ -11,6 +11,7 @@ import tify.server.domain.domains.question.domain.FavorAnswer; import tify.server.domain.domains.question.domain.FavorQuestionCategory; import tify.server.domain.domains.question.dto.model.FavorAnswerCategoryDto; +import tify.server.domain.domains.user.domain.DetailCategory; import tify.server.domain.domains.user.domain.SmallCategory; import tify.server.domain.domains.user.vo.FavorAnswerContentVo; import tify.server.domain.domains.user.vo.UserAnswerVo; @@ -50,30 +51,35 @@ public List execute(Long userId, List smallCategory .getFavorQuestion() .getNumber(), favorAnswer.getAnswerContent()))); - int userAnswerCategorySize = + + List userAnswerCategories = favorAnswerCategoryDTOs.stream() .filter( dto -> dto.getSmallCategory() .equals(smallCategory)) - .toList() - .size(); - // smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO의 개수 + .toList(); + // smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO + + List answeredDetailCategories = + userAnswerCategories.stream() + .map(FavorAnswerCategoryDto::getDetailCategory) + .toList(); - int size = - favorQuestionCategories.stream() + List notAnsweredDetailCategories = + DetailCategory.getDetailCategoriesBySmallCategory(smallCategory) + .stream() .filter( - category -> - category.getSmallCategory() - .equals(smallCategory)) - .toList() - .size(); - // smallCategory와 같은 smallCategory를 가지는 detailCategory의 개수 + detailCategory -> + !answeredDetailCategories.contains( + detailCategory)) + .toList(); return UserAnswerVo.of( smallCategory, favorAnswerContentList, - userAnswerCategorySize == size); + notAnsweredDetailCategories.isEmpty(), + notAnsweredDetailCategories); }) .toList(); } diff --git a/Core/src/main/java/tify/server/core/jwt/JwtTokenProvider.java b/Core/src/main/java/tify/server/core/jwt/JwtTokenProvider.java index d987dae0..cd776e24 100644 --- a/Core/src/main/java/tify/server/core/jwt/JwtTokenProvider.java +++ b/Core/src/main/java/tify/server/core/jwt/JwtTokenProvider.java @@ -8,10 +8,8 @@ import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.security.Keys; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.security.Key; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; @@ -167,19 +165,8 @@ public String buildAppleClientSecret() public PrivateKey getPrivateKey() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { - String result = ""; - - if (hashMap.get("apple") == null) { - File file = new File(appleKeyPath); - result = new String(Files.readAllBytes(file.toPath())); - hashMap.put("apple", result); - } else { - result = hashMap.get("apple"); - } - String key = - result.replace("-----BEGIN PRIVATE KEY-----\n", "") - .replace("-----END PRIVATE KEY-----", ""); + String key = oauthProperties.getAppleKey(); byte[] encoded = Base64.decodeBase64(key.getBytes()); diff --git a/Core/src/main/java/tify/server/core/properties/OauthProperties.java b/Core/src/main/java/tify/server/core/properties/OauthProperties.java index 977c15ec..a37a7e66 100644 --- a/Core/src/main/java/tify/server/core/properties/OauthProperties.java +++ b/Core/src/main/java/tify/server/core/properties/OauthProperties.java @@ -36,6 +36,7 @@ public static class AppleSecret { private String clientUrl; private String redirectUrl; private String keyPath; + private String key; } // base url @@ -86,4 +87,8 @@ public String getAppleRedirectUrl() { public String getAppleKeyPath() { return apple.getKeyPath(); } + + public String getAppleKey() { + return apple.getKey(); + } } diff --git a/Core/src/main/resources/application-core.yml b/Core/src/main/resources/application-core.yml index 5b0b2e22..7ff4af24 100644 --- a/Core/src/main/resources/application-core.yml +++ b/Core/src/main/resources/application-core.yml @@ -21,3 +21,4 @@ oauth2: log-in-key: ${APPLE_LOGIN_KEY} redirect-url: ${APPLE_REDIRECT} key-path: ${APPLE_KEY_PATH} + key: ${APPLE_KEY} \ No newline at end of file diff --git a/Domain/src/main/java/tify/server/domain/domains/user/domain/DetailCategory.java b/Domain/src/main/java/tify/server/domain/domains/user/domain/DetailCategory.java index ab4fad38..b59a7d5a 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/domain/DetailCategory.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/domain/DetailCategory.java @@ -33,6 +33,13 @@ public static List getDetailCategories() { return Arrays.stream(DetailCategory.values()).toList(); } + public static List getDetailCategoriesBySmallCategory( + SmallCategory smallCategory) { + return Arrays.stream(DetailCategory.values()) + .filter(detailCategory -> detailCategory.getSmallCategory().equals(smallCategory)) + .toList(); + } + final String value; final SmallCategory smallCategory; } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/vo/UserAnswerVo.java b/Domain/src/main/java/tify/server/domain/domains/user/vo/UserAnswerVo.java index b6a7e50d..08526449 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/vo/UserAnswerVo.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/vo/UserAnswerVo.java @@ -4,6 +4,7 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import tify.server.domain.domains.user.domain.DetailCategory; import tify.server.domain.domains.user.domain.SmallCategory; @Getter @@ -16,14 +17,18 @@ public class UserAnswerVo { private final boolean isAllDetailCategoryAnswered; + private final List notAnsweredDetailCategories; + public static UserAnswerVo of( SmallCategory smallCategory, List answerContentList, - boolean isAllDetailCategoryAnswered) { + boolean isAllDetailCategoryAnswered, + List detailCategories) { return UserAnswerVo.builder() .smallCategory(smallCategory) .answerContentList(answerContentList) .isAllDetailCategoryAnswered(isAllDetailCategoryAnswered) + .notAnsweredDetailCategories(detailCategories) .build(); } }