Skip to content

Commit

Permalink
deploy: deploy: app 4th Sprint2 - 익명 콕찌르기 기능 (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Jun 12, 2024
2 parents 1354218 + 2e088a1 commit f2bb7bf
Show file tree
Hide file tree
Showing 35 changed files with 2,356 additions and 416 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ out/
### application.yml 파일들에 대한 gitignore 처리
application-local.yml
application-prod.yml
application-dev.yml
application-test.yml

### HTTP 관련
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.7'
testImplementation 'org.mockito:mockito-core:4.5.1'
testImplementation 'org.mockito:mockito-junit-jupiter:4.5.1'

implementation 'net.bytebuddy:byte-buddy:1.14.15'
implementation 'org.objenesis:objenesis:3.4'

// slack
implementation 'com.slack.api:slack-api-client:1.30.0'
}
Expand Down
137 changes: 76 additions & 61 deletions src/main/java/org/sopt/app/application/auth/PlaygroundAuthInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -18,51 +19,52 @@ public class PlaygroundAuthInfo {
@Getter
@Builder
@ToString
public static class PlaygroundAccessToken {
public static class AppToken {

private String accessToken;
private String refreshToken;
}

@Getter
@Builder
@Setter
@ToString
public static class AppToken {
public static class RefreshedToken {

private String accessToken;
private String refreshToken;
private String errorCode;
}

@Getter
@Setter
@ToString
public static class PlaygroundMain {
public static class ActiveUserIds {

private Long id;
private String name;
private Long generation;
private String profileImage;
private Boolean hasProfile;
private String accessToken;
private UserStatus status;
@JsonProperty("memberIds")
private List<Long> userIds;
}

@Getter
@Setter
@Builder
@ToString
public static class PlaygroundProfile {
public static class UserActiveInfo {

private Long memberId;
private String name;
private String profileImage;
private List<PlaygroundActivity> activities;
private Long currentGeneration;
private UserStatus status;
}

@Getter
@Setter
@ToString
public static class PlaygroundActivity {
public static class PlaygroundMain {

private String cardinalInfo;
private Long id;
private String name;
private Long generation;
private String profileImage;
private Boolean hasProfile;
private String accessToken;
private UserStatus status;
}

@Getter
Expand All @@ -86,76 +88,89 @@ public static class MainViewUser {

@Getter
@Setter
@Builder
@ToString
public static class AccessToken {
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public static class PlaygroundProfile {

private String accessToken;
private Long memberId;
private String name;
private String profileImage;
private List<ActivityCardinalInfo> activities;

public ActivityCardinalInfo getLatestActivity() {
return activities.stream()
.sorted(Comparator.comparing(PlaygroundAuthInfo.ActivityCardinalInfo::getGeneration,
Comparator.reverseOrder()))
.toList()
.get(0);
}
}

@Getter
@Setter
@ToString
public static class RefreshedToken {
@Builder
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public static class ActivityCardinalInfo {

private String accessToken;
private String errorCode;
private String cardinalInfo;

public String getGeneration() {
return cardinalInfo.split(",")[0];
}

public String getPart() {
return cardinalInfo.split(",")[1];
}
}

@Getter
@Setter
@Builder
@ToString
public static class ActiveUserIds {
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public static class OwnPlaygroundProfile {

@JsonProperty("memberIds")
private List<Long> userIds;
private String mbti;
private String university;
private List<ActivityCardinalInfo> activities;
}

@Getter
@Setter
@Builder
@ToString
public static class UserActiveInfo {
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public static class PlaygroundProfileOfRecommendedFriendList {

private Long currentGeneration;
private UserStatus status;
private List<PlaygroundProfileOfRecommendedFriend> members;
}

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

@JsonProperty("memberId")
private Long id;
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
@EqualsAndHashCode(of = {"playgroundId"})
public static class PlaygroundProfileOfRecommendedFriend {

@JsonProperty("id")
private Long playgroundId;
private String mbti;
private String university;
private String profileImage;
private String name;
private List<ActivityCardinalInfo> activities;

public ActivityCardinalInfo getLatestActivity() {
return activities.stream()
.sorted(Comparator.comparing(ActivityCardinalInfo::getGeneration, Comparator.reverseOrder()))
.toList()
.get(0);
}
private List<PlaygroundActivity> activities;
}

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

private String cardinalInfo;

public String getGeneration() {
return cardinalInfo.split(",")[0];
}
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PUBLIC)
public static class PlaygroundActivity {

public String getPart() {
return cardinalInfo.split(",")[1];
}
private String part;
private Integer generation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.app.application.auth.PlaygroundAuthInfo.OwnPlaygroundProfile;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfile;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
Expand All @@ -30,6 +34,8 @@ public class PlaygroundAuthService {
private String apiKey;
@Value("${makers.playground.x-request-from}")
private String requestFrom;
@Value("${makers.playground.access-token}")
private String playgroundToken;

public PlaygroundAuthInfo.PlaygroundMain getPlaygroundInfo(String token) {
val member = this.getPlaygroundMember(token);
Expand All @@ -50,8 +56,7 @@ public AppAuthRequest.AccessTokenRequest getPlaygroundAccessToken(AppAuthRequest
}

private PlaygroundAuthInfo.PlaygroundMain getPlaygroundMember(String accessToken) {
Map<String, String> headers = createDefaultHeader();
headers.put(HttpHeaders.AUTHORIZATION, accessToken);
Map<String, String> headers = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getPlaygroundMember(headers);
} catch (ExpiredJwtException e) {
Expand Down Expand Up @@ -90,8 +95,7 @@ private UserStatus getStatus(List<Long> generationList) {
}

private PlaygroundAuthInfo.PlaygroundProfile getPlaygroundMemberProfile(String accessToken, Long playgroundId) {
Map<String, String> headers = createDefaultHeader();
headers.put(HttpHeaders.AUTHORIZATION, accessToken);
Map<String, String> headers = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getPlaygroundMemberProfile(headers, playgroundId).get(0);
} catch (BadRequest e) {
Expand Down Expand Up @@ -130,27 +134,31 @@ private Map<String, String> createDefaultHeader() {
return new HashMap<>(Map.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE));
}

public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) {
private Map<String, String> createAuthorizationHeader(String accessToken) {
Map<String, String> headers = createDefaultHeader();
headers.put(HttpHeaders.AUTHORIZATION, accessToken);
return headers;
}

public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken) {
Map<String, String> requestHeader = createAuthorizationHeader(accessToken);
try {
return playgroundClient.getPlaygroundUserIds(headers, currentGeneration);
return playgroundClient.getPlaygroundUserIds(requestHeader, currentGeneration);
} catch (BadRequest e) {
throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage());
} catch (ExpiredJwtException e) {
throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage());
}
}

public List<PlaygroundAuthInfo.MemberProfile> getPlaygroundMemberProfiles(String accessToken,
public List<PlaygroundProfile> getPlaygroundMemberProfiles(String accessToken,
List<Long> memberIds) {
Map<String, String> defaultHeader = createDefaultHeader();
defaultHeader.put(HttpHeaders.AUTHORIZATION, accessToken);
Map<String, String> requestHeader = createAuthorizationHeader(accessToken);
String stringifyIds = memberIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
try {
return playgroundClient.getMemberProfiles(defaultHeader,
return playgroundClient.getMemberProfiles(requestHeader,
URLEncoder.encode(stringifyIds, StandardCharsets.UTF_8));
} catch (BadRequest e) {
throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage());
Expand All @@ -159,4 +167,43 @@ public List<PlaygroundAuthInfo.MemberProfile> getPlaygroundMemberProfiles(String
}
}

public OwnPlaygroundProfile getOwnPlaygroundProfile(String accessToken) {
Map<String, String> requestHeader = createAuthorizationHeader(accessToken);
return playgroundClient.getOwnPlaygroundProfile(requestHeader);
}

public List<PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend> getPlaygroundProfilesForSameGeneration(
Integer generation) {
return playgroundClient.getPlaygroundProfileForSameGeneration(createAuthorizationHeader(playgroundToken),
generation).getMembers();
}

private List<PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend> getPlaygroundProfilesForGenerationRange(
Integer generation, IntFunction<List<PlaygroundProfileOfRecommendedFriend>> fetchProfilesFunction) {
List<PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend> result = new ArrayList<>();
final int TARGET_GENERATION_RANGE = 3;
for (int i = 0; i < TARGET_GENERATION_RANGE; i++) {
int targetGeneration = generation - i;
if (targetGeneration < 1) {
break;
}
result.addAll(fetchProfilesFunction.apply(targetGeneration));
}

return result.stream().distinct().toList();
}

public List<PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend> getPlaygroundProfilesForSameMbtiAndGeneration(
Integer generation, String mbti) {
return getPlaygroundProfilesForGenerationRange(generation, targetGeneration ->
playgroundClient.getPlaygroundProfileForSameMbti(createAuthorizationHeader(playgroundToken),
targetGeneration, mbti).getMembers());
}

public List<PlaygroundAuthInfo.PlaygroundProfileOfRecommendedFriend> getPlaygroundProfilesForSameUniversityAndGeneration(
Integer generation, String university) {
return getPlaygroundProfilesForGenerationRange(generation, targetGeneration ->
playgroundClient.getPlaygroundProfileForSameUniversity(createAuthorizationHeader(playgroundToken),
targetGeneration, university).getMembers());
}
}
Loading

0 comments on commit f2bb7bf

Please sign in to comment.