Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#158 get poke to me single #166

Merged
merged 21 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db07571
FIX : Playground Internal API ์ˆ˜์ • ์ŠคํŽ™ ๋ฐ˜์˜
yummygyudon Dec 9, 2023
11c1101
FEAT : ์ตœ์‹ ์ˆœ์œผ๋กœ ๋‚˜๋ฅผ ์ฐŒ๋ฅธ ๋‚ด์—ญ ์กฐํšŒ ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
yummygyudon Dec 9, 2023
eb7296e
FIX : Playgroung Internal API ๋ณ€๊ฒฝ์— ๋”ฐ๋ฅธ ์ฝ”๋“œ ๋ฐ˜์˜(DTO & UserService)
yummygyudon Dec 9, 2023
2286e4d
FEAT : ๋‚˜๋ฅผ ์ฐŒ๋ฅธ ์นœ๊ตฌ ์กฐํšŒ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ๋ฐ ์ž„์‹œ DTO ์‚ญ์ œ
yummygyudon Dec 9, 2023
098ac65
REFACTOR : Pageable ๋ฐ˜์˜ ๋ฐ Service & Repository ๊ณ„์ธต ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ
yummygyudon Dec 9, 2023
922d47b
FIX : ์นœ๊ตฌ๊ด€๊ณ„ ๊ธฐ์ค€ ํ•˜ํ•œ๊ฐ’, ์ƒํ•œ๊ฐ’ Enum์—์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์ˆ˜์ •
yummygyudon Dec 9, 2023
706ac4d
FEAT : ๊ฐ ์นœ๊ตฌ๊ด€๊ณ„๋ณ„ ๋Œ€ํ‘œ ์นœ๊ตฌ 2๋ช… ์กฐํšŒ ๊ธฐ๋Šฅ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
769add6
FEAT : ๊ฐ ์นœ๊ตฌ๊ด€๊ณ„๋ณ„ ๋Œ€ํ‘œ ์นœ๊ตฌ ์กฐํšŒ API Response DTO ํฌํ•จ ๊ธฐ๋Šฅ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
53cd187
REFACTOR : ์žฌ์‚ฌ์šฉ์„ฑ ๊ณ ๋ ค ๊ธฐ๋Šฅ ๋ฉ”์„œ๋“œ ์ฒ˜๋ฆฌ Scope ์ˆ˜์ •
yummygyudon Dec 9, 2023
76451b7
FIX : Pageable ๊ณ ๋ ค Repository ๋ฐ˜ํ™˜ ํƒ€์ž… ๋ณ€๊ฒฝ
yummygyudon Dec 9, 2023
eec9f1a
FEAT : ์š”์ฒญ Parameter ๊ฐ’์— ๋”ฐ๋ฅธ Friendship ๋ฐ˜ํ™˜ ๊ธฐ๋Šฅ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
8a07259
FEAT : Pageable ์—ฌ๋ถ€์— ๋”ฐ๋ฅธ ๋™์  ๊ธฐ๋Šฅ ์ˆ˜ํ–‰์„ ์œ„ํ•œ ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ
yummygyudon Dec 9, 2023
5571664
FEAT : ํŠน์ • ์นœ๊ตฌ๊ด€๊ณ„ ์ „์ฒด ์นœ๊ตฌ ์กฐํšŒ API Response DTO ํฌํ•จ ๊ธฐ๋Šฅ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
8d6f603
FEAT : Pageable ๋Œ€์‘ ์กฐํšŒ ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
af919c5
FIX : FriendRepository @Query ์ˆ˜์ •
yummygyudon Dec 9, 2023
5f04fa0
FEAT : ์นœ๊ตฌ ์ƒ์„ธ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ๊ธฐ๋Šฅ ๊ตฌํ˜„
yummygyudon Dec 9, 2023
8333d39
FEAT : ๋™์ผ ๋ผ์šฐํŒ… GET API์— RequestParam ์—ฌ๋ถ€์— ๋”ฐ๋ฅธ ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ๋กœ ์นœ๊ตฌ ์ƒ์„ธ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ API ๊ตฌํ˜„
yummygyudon Dec 9, 2023
d746bec
HOT FIX : PokeToMe History List API Pageable
yummygyudon Dec 10, 2023
b709de1
CHORE : ๊ฑด์‚ฌ์ฃผ(๊ฑด๋ชจ์˜ ์‚ฌ์†Œํ•œ ์ฃผ์„์ด๋ผ๋Š” ๋œป)
yummygyudon Dec 10, 2023
35a90cf
Feat/#169 get detail friend list (#170)
yummygyudon Dec 10, 2023
7c2ae7b
Feat/#167 get simple friend list (#168)
yummygyudon Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.AccessLevel;
import org.sopt.app.domain.enums.UserStatus;

public class PlaygroundAuthInfo {
Expand Down Expand Up @@ -51,15 +54,6 @@ public static class PlaygroundProfile {
private List<PlaygroundActivity> activities;
}

@Getter
@Setter
// TODO ์ž„์‹œ
@Builder
@ToString
public static class PlaygroundProfileWithId extends PlaygroundProfile {
private Long id;
}

@Getter
@Setter
@ToString
Expand Down Expand Up @@ -135,9 +129,9 @@ public static class UserActiveInfo {
}

@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class MemberProfile {
private Long id;
private String profileImage;
Expand All @@ -150,9 +144,9 @@ public ActivityCardinalInfo getLatestActivity() {
}

@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class ActivityCardinalInfo {
private String cardinalInfo;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package org.sopt.app.application.auth;

import io.jsonwebtoken.ExpiredJwtException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundActivity;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileWithId;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.domain.enums.UserStatus;
import org.sopt.app.interfaces.external.PlaygroundClient;
import org.sopt.app.presentation.auth.AppAuthRequest;
import org.sopt.app.presentation.user.UserRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException.BadRequest;
Expand Down Expand Up @@ -139,38 +136,16 @@ public PlaygroundAuthInfo.ActiveUserIds getPlayGroundUserIds(String accessToken)
public List<PlaygroundAuthInfo.MemberProfile> getPlaygroundMemberProfiles(String accessToken, List<Long> memberIds) {
Map<String, String> defaultHeader = createDefaultHeader();
defaultHeader.put("Authorization", accessToken);
UserRequest.MemberProfilesRequest request = new UserRequest.MemberProfilesRequest();
request.setMemberIds(memberIds);
String stringifyIds = memberIds.stream()
.map(String::valueOf)
.collect(Collectors.joining(","));
try {
return playgroundClient.getMemberProfiles(defaultHeader, request);
// TODO : ์ž„์‹œ Mock Data
//return List.of(new PlaygroundAuthInfo.MemberProfile(122L, null, "๊ตฌ๊ฑด๋ชจ", List.of(new PlaygroundAuthInfo.ActivityCardinalInfo("32,์›น"))));
return playgroundClient.getMemberProfiles(defaultHeader, URLEncoder.encode(stringifyIds, StandardCharsets.UTF_8));
} catch (BadRequest e) {
throw new BadRequestException(ErrorCode.PLAYGROUND_PROFILE_NOT_EXISTS.getMessage());
} catch (ExpiredJwtException e) {
throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage());
}
throw new UnauthorizedException(ErrorCode.INVALID_PLAYGROUND_TOKEN.getMessage());
}
}

public List<PlaygroundAuthInfo.PlaygroundProfileWithId> getPlaygroundProfiles(List<Long> recommendUserIds) {
val result = recommendUserIds.stream().map(
userId -> {
val dummyActivity = new PlaygroundActivity();
val dummyCardinalActivity = new PlaygroundAuthInfo.PlaygroundCardinalActivity();
dummyCardinalActivity.setGeneration(currentGeneration);
dummyCardinalActivity.setId(1L);
dummyCardinalActivity.setIsProject(false);
dummyCardinalActivity.setPart("์„œ๋ฒ„");
dummyCardinalActivity.setTeam("์—†์Œ");
dummyActivity.setCardinalActivities(List.of(dummyCardinalActivity));

val playgroundProfile = new PlaygroundProfileWithId(userId);
playgroundProfile.setProfileImage("");
playgroundProfile.setName("test");
playgroundProfile.setActivities(List.of(dummyActivity));
return playgroundProfile;
}
).toList();
return result;
}
}
36 changes: 20 additions & 16 deletions src/main/java/org/sopt/app/application/poke/FriendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@
import org.sopt.app.domain.entity.Friend;
import org.sopt.app.domain.enums.Friendship;
import org.sopt.app.interfaces.postgres.FriendRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@RequiredArgsConstructor
public class FriendService {
private static final int LIMIT_NEW_FRIEND = 2;
private static final int LIMIT_BEST_FRIEND = 5;
private static final int LIMIT_SOULMATE = 11;

private final FriendRepository friendRepository;

public List<Long> findAllFriendIdsByUserIdRandomly(Long userId, int limitNum) {
return friendRepository.getFriendRandom(userId, limitNum);
}

public List<Long> findAllFriendsByFriendship(Long userId, Integer lowerLimit, Integer upperLimit) {
return friendRepository.findAllByUserIdAndPokeCountBetweenOrderByPokeCountDesc(
userId, lowerLimit, upperLimit).stream()
.map(Friend::getFriendUserId)
.toList();
}
public Page<Friend> findAllFriendsByFriendship(Long userId, Integer lowerLimit, Integer upperLimit, Pageable pageable) {
return friendRepository.findAllByUserIdAndPokeCountBetweenOrderByPokeCountDesc(
userId, lowerLimit, upperLimit, pageable);
}


@Transactional
public void createRelation(Long pokerId, Long pokedId) {
Friend createdRelationUserToFriend = Friend.builder()
.userId(pokerId)
Expand All @@ -43,21 +51,18 @@ public void createRelation(Long pokerId, Long pokedId) {
friendRepository.save(createdRelationFriendToUser);
}

@Transactional
public void applyPokeCount(Long pokerId, Long pokedId) {
Friend friendship = friendRepository.findByUserIdAndFriendUserId(pokerId, pokedId)
.orElseThrow(() -> new NotFoundException(ErrorCode.FRIENDSHIP_NOT_FOUND.getMessage()));
friendship.addPokeCount();
}

@Transactional(readOnly = true)
public boolean isFriendEachOther(Long pokerId, Long pokedId) {
Optional<Friend> pokerToPokedRelation = friendRepository.findByUserIdAndFriendUserId(pokerId, pokedId);
Optional<Friend> pokedToPokerRelation = friendRepository.findByUserIdAndFriendUserId(pokedId, pokerId);
return pokerToPokedRelation.isPresent() && pokedToPokerRelation.isPresent();
}

@Transactional(readOnly = true)
public PokeInfo.Relationship getRelationInfo(Long pokerId, Long pokedId) {
Friend friendship = friendRepository.findByUserIdAndFriendUserId(pokerId, pokedId)
.orElseThrow(() -> new NotFoundException(ErrorCode.FRIENDSHIP_NOT_FOUND.getMessage()));
Expand All @@ -68,19 +73,18 @@ public PokeInfo.Relationship getRelationInfo(Long pokerId, Long pokedId) {
}

private String decideRelationName(Integer pokeCount) {
if (pokeCount >= LIMIT_SOULMATE) {
return Friendship.SOULMATE.getValue();
if (pokeCount >= Friendship.SOULMATE.getLowerLimit()) {
return Friendship.SOULMATE.getFriendshipName();
}
if (pokeCount >= LIMIT_BEST_FRIEND) {
return Friendship.BEST_FRIEND.getValue();
if (pokeCount >= Friendship.BEST_FRIEND.getLowerLimit()) {
return Friendship.BEST_FRIEND.getFriendshipName();
}
if (pokeCount >= LIMIT_NEW_FRIEND) {
return Friendship.NEW_FRIEND.getValue();
if (pokeCount >= Friendship.NEW_FRIEND.getLowerLimit()) {
return Friendship.NEW_FRIEND.getFriendshipName();
}
return Friendship.NON_FRIEND.getValue();
return Friendship.NON_FRIEND.getFriendshipName();
}

@Transactional(readOnly = true)
public List<Long> getMutualFriendIds(Long pokerId, Long pokedId) {
List<Long> pokerFriendIds = friendRepository.findAllOfFriendIdsByUserId(pokerId);
List<Long> pokedFriendIds = friendRepository.findAllOfFriendIdsByUserId(pokedId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.interfaces.postgres.PokeHistoryRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -39,6 +41,13 @@ public List<Long> getPokeFriendIds(Long userId) {
.toList();
}

public List<PokeHistory> getPokeFriendIdsInOrderByMostRecent(Long userId) {
return pokeHistoryRepository.findAllByPokedId(userId);
}
public Page<PokeHistory> getPokeFriendIdsInOrderByMostRecent(Long userId, Pageable pageable) {
return pokeHistoryRepository.findAllByPokedId(userId, pageable);
}

public void checkUserOverDailyPokeLimit(Long userId) {
LocalDateTime today = LocalDateTime.now();
List<PokeHistory> allByPokerIdAndCreatedAtDate = pokeHistoryRepository.findAllByPokerIdAndCreatedAt(userId, today);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/sopt/app/application/poke/PokeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public Boolean isReplyPoke(Long pokerId, Long pokedId) {

@Transactional(readOnly = true)
public PokeInfo.PokeDetail getPokeDetail(Long pokerId, Long pokedId) {
PokeHistory latestPokeHistory = historyRepository.findAllByPokerIdAndPokedIdOrderByCreatedAtDesc(pokerId, pokedId).get(0);
PokeHistory latestPokeHistory = historyRepository.findAllByPokerIdAndPokedIdOrderByCreatedAtDesc(pokerId, pokedId).stream()
.distinct()
.findFirst()
.orElseThrow(() -> new NotFoundException(ErrorCode.POKE_HISTORY_NOT_FOUND.getMessage()));
return PokeInfo.PokeDetail.builder()
.id(latestPokeHistory.getId())
.message(latestPokeHistory.getMessage())
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/org/sopt/app/application/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.app.application.auth.PlaygroundAuthInfo;
import org.sopt.app.application.auth.PlaygroundAuthInfo.PlaygroundProfileWithId;
import org.sopt.app.application.user.UserInfo.PokeProfile;
import org.sopt.app.application.user.UserInfo.UserProfile;
import org.sopt.app.common.exception.UnauthorizedException;
Expand Down Expand Up @@ -94,19 +93,19 @@ public void updatePlaygroundToken(UserInfo.Id userId, String playgroundToken) {
}

@Transactional(readOnly = true)
public UserInfo.UserProfile getUserProfile(Long userId) {
public UserProfile getUserProfile(Long userId) {
val user = userRepository.findUserById(userId)
.orElseThrow(() -> new UnauthorizedException(ErrorCode.USER_NOT_FOUND.getMessage()));
return UserInfo.UserProfile.builder()
return UserProfile.builder()
.userId(user.getId())
.name(user.getUsername())
.playgroundId(user.getPlaygroundId())
.build();
}

public List<UserInfo.UserProfile> getUserProfilesByPlaygroundIds(List<Long> playgroundIds) {
public List<UserProfile> getUserProfilesByPlaygroundIds(List<Long> playgroundIds) {
return userRepository.findAllByPlaygroundIdIn(playgroundIds).stream().map(
u -> UserInfo.UserProfile.builder()
u -> UserProfile.builder()
.userId(u.getId())
.name(u.getUsername())
.playgroundId(u.getPlaygroundId())
Expand All @@ -125,28 +124,26 @@ public List<UserProfile> getUserProfileByUserId(List<Long> userId) {
}

public List<PokeProfile> combinePokeProfileList(
List<UserProfile> userProfiles, List<PlaygroundProfileWithId> playgroundProfiles
List<UserProfile> userProfiles, List<PlaygroundAuthInfo.MemberProfile> playgroundProfiles
) {
return userProfiles.stream().map(userProfile -> {
val playgroundProfile = playgroundProfiles.stream()
.filter(profile -> profile.getId().equals(userProfile.getPlaygroundId()))
.findFirst()
.orElseThrow(() -> new RuntimeException("ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ํ”„๋กœํ•„์ด ์—†์Šต๋‹ˆ๋‹ค."));
val generation = playgroundProfile.getActivities().get(0).getCardinalActivities().get(0)
.getGeneration();
val part = playgroundProfile.getActivities().get(0).getCardinalActivities().get(0)
.getPart();
val generation = playgroundProfile.getActivities().get(0).getGeneration();
val part = playgroundProfile.getActivities().get(0).getPart();
return PokeProfile.builder()
.userId(userProfile.getUserId())
.profileImage(playgroundProfile.getProfileImage())
.name(userProfile.getName())
.generation(generation)
.generation(Long.parseLong(generation))
.part(part)
.isAlreadyPoked(false)
.build();
}).toList();
}
public List<UserInfo.UserProfile> findRandomFriendsOfFriends(Long userId, Long friendIds, int limitNum) {
public List<UserProfile> findRandomFriendsOfFriends(Long userId, Long friendIds, int limitNum) {
val users = userRepository.findRandomFriendsOfFriends(userId, friendIds, limitNum);
return users.stream().map(
u -> UserProfile.builder()
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sopt/app/common/response/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public enum ErrorCode {
POKE_MESSAGE_NOT_FOUND("ํ•ด๋‹น ์ฐŒ๋ฅด๊ธฐ ๋ฉ”์‹œ์ง€๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
OVER_DAILY_POKE_LIMIT("์ผ์ผ ์ตœ๋Œ€ ์ฐŒ๋ฅด๊ธฐ ๊ฐ€๋Šฅ ํšŸ์ˆ˜๋ฅผ ์ดˆ๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค."),


// FRIEND
FRIENDSHIP_NOT_FOUND("ํ•ด๋‹น ์นœ๊ตฌ๊ด€๊ณ„๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/sopt/app/domain/enums/Friendship.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package org.sopt.app.domain.enums;

import lombok.*;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.response.ErrorCode;

import java.util.Arrays;

@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum Friendship {
NON_FRIEND(""), NEW_FRIEND("์นœํ•œ์นœ๊ตฌ"), BEST_FRIEND("๋‹จ์ง์นœ๊ตฌ"), SOULMATE("์ฒœ์ƒ์—ฐ๋ถ„")
NON_FRIEND("","", 0,1),
NEW_FRIEND("NF","์นœํ•œ์นœ๊ตฌ",2, 4),
BEST_FRIEND("BF","๋‹จ์ง์นœ๊ตฌ",5,10),
SOULMATE("SM","์ฒœ์ƒ์—ฐ๋ถ„",11,99)
;

private final String value;
private final String typeFlag;
private final String friendshipName;
private final Integer lowerLimit;
private final Integer upperLimit;

public static Friendship getFriendshipByValue(String type) {
return Arrays.stream(values())
.filter(friendship -> friendship.getTypeFlag().equals(type))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.FRIENDSHIP_NOT_FOUND.getMessage()));
}
}
Loading