Skip to content

Commit

Permalink
Revert "v1.195" of staging
Browse files Browse the repository at this point in the history
Revert "v1.195"
  • Loading branch information
euije authored Sep 12, 2023
2 parents c2b76f9 + c620f86 commit def0028
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 193 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yello.server.domain.friend.service;

import static com.yello.server.global.common.ErrorCode.EXIST_FRIEND_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.LACK_USER_EXCEPTION;
import static com.yello.server.global.common.util.ConstantUtil.RANDOM_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.YELLO_FEMALE;
import static com.yello.server.global.common.util.ConstantUtil.YELLO_MALE;

Expand All @@ -18,7 +20,6 @@
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.repository.VoteRepository;
import com.yello.server.domain.vote.service.VoteManager;
import com.yello.server.global.common.factory.PaginationFactory;
import java.lang.Character.UnicodeBlock;
import java.util.ArrayList;
Expand All @@ -42,7 +43,6 @@ public class FriendService {
private final FriendRepository friendRepository;
private final UserRepository userRepository;
private final VoteRepository voteRepository;
private final VoteManager voteManager;

public FriendsResponse findAllFriends(Pageable pageable, Long userId) {
final Page<Friend> friendsData = friendRepository.findAllFriendsByUserId(pageable, userId);
Expand Down Expand Up @@ -77,7 +77,20 @@ public Friend addFriend(Long userId, Long targetId) {
public List<FriendShuffleResponse> findShuffledFriend(Long userId) {
final User user = userRepository.getById(userId);

return voteManager.getShuffledFriends(user);
final List<Friend> friends =
new ArrayList<>(friendRepository.findAllByUserId(user.getId()));
List<Friend> friendList = new ArrayList<>(friends);

if (friendList.size() < RANDOM_COUNT) {
throw new FriendException(LACK_USER_EXCEPTION);
}

Collections.shuffle(friendList);

return friendList.stream()
.map(FriendShuffleResponse::of)
.limit(RANDOM_COUNT)
.toList();
}

public RecommendFriendResponse findAllRecommendSchoolFriends(Pageable pageable, Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ void handleAppleTransactionError(ResponseEntity<TransactionInfoResponse> respons

void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO);

void refundAppleInApp(AppleNotificationPayloadVO payloadVO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import static com.yello.server.global.common.ErrorCode.APPLE_TOKEN_SERVER_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.GOOGLE_SUBSCRIPTIONS_SUBSCRIPTION_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.NOT_FOUND_TRANSACTION_EXCEPTION;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_FIVE_TICKET;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_ONE_TICKET;
import static com.yello.server.global.common.util.ConstantUtil.REFUND_TWO_TICKET;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yello.server.domain.purchase.dto.apple.AppleNotificationPayloadVO;
Expand Down Expand Up @@ -71,7 +68,7 @@ public void handleAppleTransactionError(ResponseEntity<TransactionInfoResponse>

@Override
public AppleNotificationPayloadVO decodeApplePayload(String signedPayload) {

Map<String, Object> jsonPayload = DecodeTokenFactory.decodeToken(signedPayload);
ObjectMapper objectMapper = new ObjectMapper();

Expand Down Expand Up @@ -120,35 +117,5 @@ public void changeSubscriptionStatus(AppleNotificationPayloadVO payloadVO) {
}
}

@Override
public void refundAppleInApp(AppleNotificationPayloadVO payloadVO) {
String transactionId =
decodeAppleNotificationData(payloadVO.data().signedTransactionInfo());
Purchase purchase = purchaseRepository.findByTransactionId(transactionId)
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_TRANSACTION_EXCEPTION));
User user = purchase.getUser();

switch (purchase.getProductType()) {
case YELLO_PLUS -> {
user.setSubscribe(Subscribe.NORMAL);
}
case ONE_TICKET -> {
validateTicketCount(REFUND_ONE_TICKET, user);
}
case TWO_TICKET -> {
validateTicketCount(REFUND_TWO_TICKET, user);
}
case FIVE_TICKET -> {
validateTicketCount(REFUND_FIVE_TICKET, user);
}
}
}

public void validateTicketCount(int ticketCount, User user) {
if (user.getTicketCount() >= ticketCount) {
user.setTicketCount(-Math.abs(ticketCount));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void verifyAppleSubscriptionTransaction(Long userId,
}

purchaseManager.createSubscribe(user, Gateway.APPLE, request.transactionId());
user.setTicketCount(3);
user.addTicketCount(3);
}

@Transactional
Expand All @@ -126,17 +126,17 @@ public void verifyAppleTicketTransaction(Long userId, AppleTransaction request)
case ONE_TICKET_ID:
purchaseManager.createTicket(user, ProductType.ONE_TICKET, Gateway.APPLE,
request.transactionId());
user.setTicketCount(1);
user.addTicketCount(1);
break;
case TWO_TICKET_ID:
purchaseManager.createTicket(user, ProductType.TWO_TICKET, Gateway.APPLE,
request.transactionId());
user.setTicketCount(2);
user.addTicketCount(2);
break;
case FIVE_TICKET_ID:
purchaseManager.createTicket(user, ProductType.FIVE_TICKET, Gateway.APPLE,
request.transactionId());
user.setTicketCount(5);
user.addTicketCount(5);
break;
default:
throw new PurchaseException(NOT_FOUND_TRANSACTION_EXCEPTION);
Expand Down Expand Up @@ -206,7 +206,7 @@ public GoogleSubscriptionGetResponse verifyGoogleSubscriptionTransaction(Long us
case ConstantUtil.GOOGLE_PURCHASE_SUBSCRIPTION_ACTIVE -> {
final Purchase subscribe =
purchaseManager.createSubscribe(user, Gateway.GOOGLE, request.orderId());
user.setTicketCount(3);
user.addTicketCount(3);
subscribe.setTransactionId(request.orderId());
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public GoogleTicketGetResponse verifyGoogleTicketTransaction(Long userId,
Purchase ticket =
purchaseManager.createTicket(user, getProductType(request.productId()),
Gateway.GOOGLE, request.orderId());
user.setTicketCount(getTicketAmount(request.productId()) * request.quantity());
user.addTicketCount(getTicketAmount(request.productId()) * request.quantity());
ticket.setTransactionId(inAppResponse.getBody().orderId());
} else {
throw new GoogleBadRequestException(GOOGLE_INAPP_BAD_REQUEST_EXCEPTION);
Expand Down Expand Up @@ -304,7 +304,7 @@ public void appleNotification(AppleNotificationRequest request) {
purchaseManager.changeSubscriptionStatus(payloadVO);
break;
case APPLE_NOTIFICATION_REFUND:
purchaseManager.refundAppleInApp(payloadVO);
System.out.println("dd");
break;
case APPLE_NOTIFICATION_TEST:
return;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/yello/server/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public static User of(SignUpRequest signUpRequest, School group) {
.group(group)
.groupAdmissionYear(signUpRequest.groupAdmissionYear())
.email(signUpRequest.email())
.deviceToken(Objects.equals(signUpRequest.deviceToken(), "") ? null
: signUpRequest.deviceToken())
.deviceToken(Objects.equals(signUpRequest.deviceToken(), "") ? null : signUpRequest.deviceToken())
.subscribe(Subscribe.NORMAL)
.ticketCount(0)
.build();
Expand Down Expand Up @@ -168,7 +167,7 @@ public void increaseRecommendPoint() {
}

public void plusPoint(Integer point) {
if (this.getSubscribe()==Subscribe.NORMAL) {
if (this.getSubscribe() == Subscribe.NORMAL) {
this.point += point;
return;
}
Expand All @@ -195,7 +194,7 @@ public void setSubscribe(Subscribe subscribe) {
this.subscribe = subscribe;
}

public void setTicketCount(int ticketCount) {
public void addTicketCount(int ticketCount) {
this.ticketCount += ticketCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
public record VoteAvailableResponse(
Boolean isPossible,
Integer point,
String createdAt,
Integer friendStatus
String createdAt
) {

public static VoteAvailableResponse of(User user, Cooldown cooldown, Integer friendStatus) {
public static VoteAvailableResponse of(User user, Cooldown cooldown) {
return VoteAvailableResponse.builder()
.isPossible(cooldown.isPossible())
.point(user.getPoint())
.createdAt(toDateFormattedString(cooldown.getCreatedAt()))
.friendStatus(friendStatus)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yello.server.domain.vote.service;

import com.yello.server.domain.friend.dto.response.FriendShuffleResponse;
import com.yello.server.domain.keyword.dto.response.KeywordCheckResponse;
import com.yello.server.domain.question.dto.response.QuestionForVoteResponse;
import com.yello.server.domain.question.entity.Question;
Expand All @@ -20,7 +19,4 @@ public interface VoteManager {
KeywordCheckResponse useKeywordHint(User user, Vote vote);

void makeGreetingVote(User user);

List<FriendShuffleResponse> getShuffledFriends(User user);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import static com.yello.server.global.common.ErrorCode.DUPLICATE_VOTE_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.INVALID_VOTE_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.LACK_POINT_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.LACK_USER_EXCEPTION;
import static com.yello.server.global.common.factory.WeightedRandomFactory.randomPoint;
import static com.yello.server.global.common.util.ConstantUtil.KEYWORD_HINT_POINT;
import static com.yello.server.global.common.util.ConstantUtil.NAME_HINT_DEFAULT;
import static com.yello.server.global.common.util.ConstantUtil.NAME_HINT_POINT;
import static com.yello.server.global.common.util.ConstantUtil.NO_FRIEND_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.RANDOM_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.VOTE_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.YELLO_FEMALE;
import static com.yello.server.global.common.util.ConstantUtil.YELLO_MALE;

import com.yello.server.domain.friend.dto.response.FriendShuffleResponse;
import com.yello.server.domain.friend.entity.Friend;
import com.yello.server.domain.friend.exception.FriendException;
import com.yello.server.domain.friend.repository.FriendRepository;
import com.yello.server.domain.keyword.dto.response.KeywordCheckResponse;
import com.yello.server.domain.keyword.entity.Keyword;
Expand Down Expand Up @@ -110,19 +107,19 @@ public List<QuestionForVoteResponse> generateVoteQuestion(User user, List<Questi

@Override
public int useNameHint(User sender, Vote vote) {
if (sender.getPoint() < NAME_HINT_POINT && sender.getSubscribe()==Subscribe.NORMAL) {
if (sender.getPoint() < NAME_HINT_POINT && sender.getSubscribe() == Subscribe.NORMAL) {
throw new VoteForbiddenException(LACK_POINT_EXCEPTION);
}

if (vote.getNameHint()!=NAME_HINT_DEFAULT) {
if (vote.getNameHint() != NAME_HINT_DEFAULT) {
throw new VoteNotFoundException(INVALID_VOTE_EXCEPTION);
}

final ThreadLocalRandom random = ThreadLocalRandom.current();
int randomIndex = random.nextInt(2);
vote.checkNameIndexOf(randomIndex);

if (sender.getSubscribe()==Subscribe.NORMAL) {
if (sender.getSubscribe() == Subscribe.NORMAL) {
sender.minusPoint(NAME_HINT_POINT);
return randomIndex;
}
Expand Down Expand Up @@ -163,35 +160,24 @@ public void makeGreetingVote(User user) {
voteRepository.save(createFirstVote(sender, user, greetingQuestion));
}

@Override
public List<FriendShuffleResponse> getShuffledFriends(User user) {
private boolean isDuplicatedVote(int index, List<VoteAnswer> voteAnswers) {
return index > 0 && voteAnswers.get(index - 1).questionId()
.equals(voteAnswers.get(index).questionId());
}

private List<FriendShuffleResponse> getShuffledFriends(User user) {
List<String> uuidList = Arrays.asList(YELLO_FEMALE, YELLO_MALE);
final List<Friend> friends = friendRepository.findAllByUserIdNotIn(user.getId(), uuidList);

List<Friend> friendList = new ArrayList<>(friends);
Collections.shuffle(friendList);

if (friends.size()==NO_FRIEND_COUNT) {
throw new FriendException(LACK_USER_EXCEPTION);
}

if (friends.size() > NO_FRIEND_COUNT && friends.size() < RANDOM_COUNT) {
return friendList.stream()
.map(FriendShuffleResponse::of)
.toList();
}

return friendList.stream()
.map(FriendShuffleResponse::of)
.limit(RANDOM_COUNT)
.toList();
}

private boolean isDuplicatedVote(int index, List<VoteAnswer> voteAnswers) {
return index > 0 && voteAnswers.get(index - 1).questionId()
.equals(voteAnswers.get(index).questionId());
}

private List<String> getShuffledKeywords(Question question) {
final List<Keyword> keywords = question.getKeywordList();
List<Keyword> keywordList = new ArrayList<>(keywords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static com.yello.server.global.common.util.ConstantUtil.CHECK_FULL_NAME;
import static com.yello.server.global.common.util.ConstantUtil.COOL_DOWN_TIME;
import static com.yello.server.global.common.util.ConstantUtil.MINUS_TICKET_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.NO_FRIEND_COUNT;
import static com.yello.server.global.common.util.ConstantUtil.RANDOM_COUNT;

import com.yello.server.domain.cooldown.entity.Cooldown;
Expand Down Expand Up @@ -123,7 +122,7 @@ public List<QuestionForVoteResponse> findVoteQuestionList(Long userId) {
final User user = userRepository.getById(userId);

final List<Friend> friends = friendRepository.findAllByUserId(user.getId());
if (friends.size()==NO_FRIEND_COUNT) {
if (friends.size() < RANDOM_COUNT) {
throw new FriendException(LACK_USER_EXCEPTION);
}

Expand All @@ -145,18 +144,14 @@ public VoteAvailableResponse checkVoteAvailable(Long userId) {
final String messageId = UUID.randomUUID().toString();
final List<Friend> friends = friendRepository.findAllByUserId(user.getId());

if (friends.size()==NO_FRIEND_COUNT) {
if (friends.size() < RANDOM_COUNT) {
throw new FriendException(LACK_USER_EXCEPTION);
}

final Cooldown cooldown = cooldownRepository.findByUserId(user.getId())
.orElse(Cooldown.of(user, messageId, minusTime(LocalDateTime.now(), COOL_DOWN_TIME)));

if (friends.size() > NO_FRIEND_COUNT && friends.size() < RANDOM_COUNT) {
return VoteAvailableResponse.of(user, cooldown, 0);
}

return VoteAvailableResponse.of(user, cooldown, 1);
return VoteAvailableResponse.of(user, cooldown);
}

@Transactional
Expand Down Expand Up @@ -200,7 +195,7 @@ public RevealFullNameResponse revealFullName(Long userId, Long voteId) {
}

vote.checkNameIndexOf(CHECK_FULL_NAME);
sender.setTicketCount(MINUS_TICKET_COUNT);
sender.addTicketCount(MINUS_TICKET_COUNT);

return RevealFullNameResponse.of(vote.getSender());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum ErrorCode {
REQUEST_VALIDATION_EXCEPTION(BAD_REQUEST, "잘못된 요청입니다."),
YELLOID_REQUIRED_EXCEPTION(BAD_REQUEST, "쿼리 스트링에 yelloId를 포함해야 합니다."),
OAUTH_ACCESS_TOKEN_REQUIRED_EXCEPTION(BAD_REQUEST, "소셜 액세스 토큰이 없습니다."),
LACK_USER_EXCEPTION(BAD_REQUEST, "친구가 부족합니다."),
LACK_USER_EXCEPTION(BAD_REQUEST, "친구가 4명 이하입니다."),
SIGNIN_FIELD_REQUIRED_EXCEPTION(BAD_REQUEST, "회원가입에 필요한 값이 없습니다."),
FIELD_REQUIRED_EXCEPTION(BAD_REQUEST, "필요한 값이 없습니다."),
INVALID_VOTE_EXCEPTION(BAD_REQUEST, "이미 공개한 투표입니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public class ConstantUtil {
public static final String APPLE_NOTIFICATION_TEST = "TEST";
public static final String APPLE_SUBTYPE_AUTO_RENEW_DISABLED = "AUTO_RENEW_DISABLED";
public static final String APPLE_SUBTYPE_VOLUNTARY = "VOLUNTARY";
public static final int REFUND_ONE_TICKET = 1;
public static final int REFUND_TWO_TICKET = 2;
public static final int REFUND_FIVE_TICKET = 5;
public static final int NO_FRIEND_COUNT = 0;


private ConstantUtil() {
Expand Down
Loading

0 comments on commit def0028

Please sign in to comment.