Skip to content

Commit

Permalink
[FEATURE] 유저 취향 답변 중분류 별 조회 API 필드 변경 (#141)
Browse files Browse the repository at this point in the history
* feat : 유저 취향 답변 중분류 별 조회 API 필드 변경 & 로직 리팩토링

* edit : 애플 로그인 키 로직 변경
  • Loading branch information
bongsh0112 authored Dec 27, 2023
1 parent 87d1a98 commit 1bf4674
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,30 +51,35 @@ public List<UserAnswerVo> execute(Long userId, List<SmallCategory> smallCategory
.getFavorQuestion()
.getNumber(),
favorAnswer.getAnswerContent())));
int userAnswerCategorySize =

List<FavorAnswerCategoryDto> userAnswerCategories =
favorAnswerCategoryDTOs.stream()
.filter(
dto ->
dto.getSmallCategory()
.equals(smallCategory))
.toList()
.size();
// smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO의 개수
.toList();
// smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO

List<DetailCategory> answeredDetailCategories =
userAnswerCategories.stream()
.map(FavorAnswerCategoryDto::getDetailCategory)
.toList();

int size =
favorQuestionCategories.stream()
List<DetailCategory> 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();
}
Expand Down
15 changes: 1 addition & 14 deletions Core/src/main/java/tify/server/core/jwt/JwtTokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class AppleSecret {
private String clientUrl;
private String redirectUrl;
private String keyPath;
private String key;
}

// base url
Expand Down Expand Up @@ -86,4 +87,8 @@ public String getAppleRedirectUrl() {
public String getAppleKeyPath() {
return apple.getKeyPath();
}

public String getAppleKey() {
return apple.getKey();
}
}
1 change: 1 addition & 0 deletions Core/src/main/resources/application-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ oauth2:
log-in-key: ${APPLE_LOGIN_KEY}
redirect-url: ${APPLE_REDIRECT}
key-path: ${APPLE_KEY_PATH}
key: ${APPLE_KEY}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public static List<DetailCategory> getDetailCategories() {
return Arrays.stream(DetailCategory.values()).toList();
}

public static List<DetailCategory> getDetailCategoriesBySmallCategory(
SmallCategory smallCategory) {
return Arrays.stream(DetailCategory.values())
.filter(detailCategory -> detailCategory.getSmallCategory().equals(smallCategory))
.toList();
}

final String value;
final SmallCategory smallCategory;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,14 +17,18 @@ public class UserAnswerVo {

private final boolean isAllDetailCategoryAnswered;

private final List<DetailCategory> notAnsweredDetailCategories;

public static UserAnswerVo of(
SmallCategory smallCategory,
List<FavorAnswerContentVo> answerContentList,
boolean isAllDetailCategoryAnswered) {
boolean isAllDetailCategoryAnswered,
List<DetailCategory> detailCategories) {
return UserAnswerVo.builder()
.smallCategory(smallCategory)
.answerContentList(answerContentList)
.isAllDetailCategoryAnswered(isAllDetailCategoryAnswered)
.notAnsweredDetailCategories(detailCategories)
.build();
}
}

0 comments on commit 1bf4674

Please sign in to comment.