Skip to content

Commit

Permalink
deploy: 핫게시물 반환 기능 main 배포 (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Jul 28, 2024
2 parents a169d57 + 7768dfb commit c48fd03
Show file tree
Hide file tree
Showing 105 changed files with 1,462 additions and 1,087 deletions.
6 changes: 0 additions & 6 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
## 🚀 Issue Summary


#### 🚗 Implement TODO
- [ ]
- [ ]


#### 🚓 Remarks

11 changes: 4 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
## 📝 PR Summary


#### 🌵 Working Branch


#### 🌴 Works
- [ ]
- [ ]

- [x]

#### 🌱 Related Issue
closed #

#### 🌵 PR 참고사항
-
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.app.application.service;
package org.sopt.app.application.app_service;

import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.app.application.service;
package org.sopt.app.application.app_service;

import java.util.Comparator;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CustomUserDetailService implements UserDetailsService {
private final UserRepository userRepository;

public UserDetails loadUserByUsername(String username) throws NotFoundException {
return (UserDetails) userRepository.findUserById(Long.parseLong(username))
return userRepository.findUserById(Long.parseLong(username))
.orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
Expand All @@ -15,7 +14,8 @@
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.joda.time.LocalDateTime;
import org.sopt.app.application.auth.PlaygroundAuthInfo.AppToken;
import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.AppToken;
import org.sopt.app.application.auth.dto.PlaygroundProfileInfo;
import org.sopt.app.application.user.UserInfo;
import org.sopt.app.common.exception.UnauthorizedException;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -40,8 +40,8 @@ private Key getSigningKey(String keyString) {
return Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey));
}

public PlaygroundAuthInfo.AppToken issueNewTokens(UserInfo.Id userId,
PlaygroundAuthInfo.PlaygroundMain playgroundMember) {
public AppToken issueNewTokens(UserInfo.Id userId,
PlaygroundProfileInfo.PlaygroundMain playgroundMember) {
val accessToken = this.encodeJwtToken(userId, playgroundMember.getId());
val refreshToken = this.encodeJwtRefreshToken(userId);
return AppToken.builder().accessToken(accessToken).refreshToken(refreshToken).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
import java.util.stream.IntStream;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile;
import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendFilter;
import org.sopt.app.application.auth.PlaygroundAuthInfo.RecommendFriendRequest;
import org.sopt.app.application.auth.dto.PlaygroundAuthTokenInfo.RefreshedToken;
import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPost;
import org.sopt.app.application.auth.dto.PlaygroundPostInfo.PlaygroundPostResponse;
import org.sopt.app.application.auth.dto.PlaygroundProfileInfo;
import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.MainView;
import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.OwnPlaygroundProfile;
import org.sopt.app.application.auth.dto.PlaygroundProfileInfo.PlaygroundProfile;
import org.sopt.app.application.auth.dto.RecommendFriendRequest;
import org.sopt.app.application.auth.dto.RecommendedFriendInfo.RecommendFriendFilter;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
Expand All @@ -40,8 +45,11 @@ public class PlaygroundAuthService {
private String requestFrom;
@Value("${makers.playground.access-token}")
private String playgroundToken;
@Value("${makers.playground.web-page}")
private String playgroundWebPageUrl;

public PlaygroundAuthInfo.PlaygroundMain getPlaygroundInfo(String token) {

public PlaygroundProfileInfo.PlaygroundMain getPlaygroundInfo(String token) {
val member = this.getPlaygroundMember(token);
val playgroundProfile = this.getPlaygroundMemberProfile(token, member.getId());
val generationList = this.getMemberGenerationList(playgroundProfile);
Expand All @@ -59,7 +67,7 @@ public AppAuthRequest.AccessTokenRequest getPlaygroundAccessToken(AppAuthRequest
}
}

private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken) {
private PlaygroundProfileInfo.PlaygroundMain getPlaygroundMember(String accessToken) {
Map<String, String> headers = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getPlaygroundMember(headers);
Expand All @@ -70,7 +78,7 @@ private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken
}
}

public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.AccessTokenRequest tokenRequest) {
public RefreshedToken refreshPlaygroundToken(AppAuthRequest.AccessTokenRequest tokenRequest) {
Map<String, String> headers = createDefaultHeader();
headers.put("x-api-key", apiKey);
headers.put("x-request-from", requestFrom);
Expand All @@ -81,24 +89,24 @@ public PlaygroundAuthInfo.RefreshedToken refreshPlaygroundToken(AppAuthRequest.A
}
}

public PlaygroundAuthInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) {
public PlaygroundProfileInfo.MainView getPlaygroundUserForMainView(String accessToken, Long playgroundId) {
val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId);
val profileImage = playgroundProfile.getProfileImage() == null ? "" : playgroundProfile.getProfileImage();
val generationList = this.getMemberGenerationList(playgroundProfile);
val mainViewUser = PlaygroundAuthInfo.MainViewUser.builder()
val mainViewUser = PlaygroundProfileInfo.MainViewUser.builder()
.status(this.getStatus(generationList))
.name(playgroundProfile.getName())
.profileImage(profileImage)
.generationList(generationList)
.build();
return PlaygroundAuthInfo.MainView.builder().user(mainViewUser).build();
return new MainView(mainViewUser);
}

private UserStatus getStatus(List<Long> generationList) {
return generationList.contains(currentGeneration) ? UserStatus.ACTIVE : UserStatus.INACTIVE;
}

private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) {
private PlaygroundProfileInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) {
Map<String, String> headers = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getSinglePlaygroundMemberProfile(headers, playgroundId).get(0);
Expand All @@ -109,17 +117,14 @@ private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String a
}
}

public PlaygroundAuthInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) {
public PlaygroundProfileInfo.UserActiveInfo getPlaygroundUserActiveInfo(String accessToken, Long playgroundId) {
val playgroundProfile = this.getPlaygroundMemberProfile(accessToken, playgroundId);
val generationList = this.getMemberGenerationList(playgroundProfile);
val userStatus = this.getStatus(generationList);
return PlaygroundAuthInfo.UserActiveInfo.builder()
.status(userStatus)
.currentGeneration(currentGeneration)
.build();
return new PlaygroundProfileInfo.UserActiveInfo(currentGeneration, userStatus);
}

private List<Long> getMemberGenerationList(PlaygroundAuthInfo.PlaygroundProfile playgroundProfile) {
private List<Long> getMemberGenerationList(PlaygroundProfileInfo.PlaygroundProfile playgroundProfile) {
return playgroundProfile.getActivities().stream()
.map(activity ->
{
Expand All @@ -144,7 +149,7 @@ private Map<String, String> createAuthorizationHeader(String accessToken) {
return headers;
}

public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) {
public PlaygroundProfileInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) {
Map<String, String> requestHeader = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getPlaygroundUserIds(requestHeader, currentGeneration);
Expand Down Expand Up @@ -181,7 +186,7 @@ public List<Long> getPlaygroundIdsForSameGeneration(List<Integer> generationList
return playgroundClient.getPlaygroundUserIdsForSameRecommendType(
createAuthorizationHeader(playgroundToken),
RecommendFriendRequest.createRecommendFriendRequestByGeneration(generationList)
).getUserIds();
).userIds();
}

private List<Integer> getGenerationListByLatestGenerationForRange(Integer latestGeneration) {
Expand All @@ -191,24 +196,38 @@ private List<Integer> getGenerationListByLatestGenerationForRange(Integer latest
}

public List<Long> getPlaygroundIdsForSameMbti(Integer latestGeneration, String mbti) {
RecommendFriendRequest request = RecommendFriendRequest.builder()
.generations(getGenerationListByLatestGenerationForRange(latestGeneration))
.filters(List.of(RecommendFriendFilter.builder().key(String.valueOf(MBTI)).value(mbti).build()))
.build();
List<Integer> targetGenerations = getGenerationListByLatestGenerationForRange(latestGeneration);
List<RecommendFriendFilter> filters =
List.of(RecommendFriendFilter.builder().key(String.valueOf(MBTI)).value(mbti).build());

return playgroundClient.getPlaygroundUserIdsForSameRecommendType(
createAuthorizationHeader(playgroundToken),
request
).getUserIds();
new RecommendFriendRequest(targetGenerations, filters)
).userIds();
}

public List<Long> getPlaygroundIdsForSameUniversity(Integer latestGeneration, String university) {
RecommendFriendRequest request = RecommendFriendRequest.builder()
.generations(getGenerationListByLatestGenerationForRange(latestGeneration))
.filters(List.of(RecommendFriendFilter.builder().key(String.valueOf(UNIVERSITY)).value(university).build()))
.build();
List<Integer> targetGenerations = getGenerationListByLatestGenerationForRange(latestGeneration);
List<RecommendFriendFilter> filters =
List.of(RecommendFriendFilter.builder().key(String.valueOf(UNIVERSITY)).value(university).build());

return playgroundClient.getPlaygroundUserIdsForSameRecommendType(
createAuthorizationHeader(playgroundToken),
request
).getUserIds();
new RecommendFriendRequest(targetGenerations, filters)
).userIds();
}

public PlaygroundPost getPlaygroundHotPost(String playgroundToken) {
PlaygroundPostResponse postInfo = playgroundClient.getPlaygroundHotPost(createAuthorizationHeader(playgroundToken));

return PlaygroundPost.builder()
.title(postInfo.title())
.content(postInfo.content())
.url(convertPlaygroundWebPageUrl(postInfo.postId()))
.build();
}

private String convertPlaygroundWebPageUrl(Long postId) {
return playgroundWebPageUrl + "/?feed=" + postId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sopt.app.application.auth.dto;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PlaygroundAuthTokenInfo {

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class AppToken {

private String accessToken;
private String refreshToken;
}

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class RefreshedToken {

private String accessToken;
private String errorCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sopt.app.application.auth.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PlaygroundPostInfo {

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class PlaygroundPost {

private String title;
private String content;
private String url;
}

public record PlaygroundPostResponse(
@JsonProperty(value = "id")
Long postId,
String title,
String content
) {
}
}
Loading

0 comments on commit c48fd03

Please sign in to comment.