diff --git a/src/main/java/com/jangburich/domain/store/service/PrepayService.java b/src/main/java/com/jangburich/domain/store/service/PrepayService.java index f75a0ae..1d714f8 100644 --- a/src/main/java/com/jangburich/domain/store/service/PrepayService.java +++ b/src/main/java/com/jangburich/domain/store/service/PrepayService.java @@ -1,6 +1,9 @@ package com.jangburich.domain.store.service; +<<<<<<< Updated upstream import java.time.LocalDate; +======= +>>>>>>> Stashed changes import java.util.Optional; import org.springframework.stereotype.Service; @@ -47,6 +50,7 @@ public Message prepay(String userId, PrepayRequest prepayRequest) { Store store = storeRepository.findById(prepayRequest.storeId()) .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 가게 id 입니다.")); +<<<<<<< Updated upstream team.validateIsTeamLeader(team.getTeamLeader().getUser_id(), user.getUserId()); user.validateHasPointWithPrepayAmount(prepayRequest.prepayAmount(), user.getPoint()); @@ -92,8 +96,52 @@ public Message prepay(String userId, PrepayRequest prepayRequest) { } StoreTeam storeTeam = storeAndTeam.get(); + storeTeam.setPersonalAllocatedPoint(prepayRequest.personalAllocatedAmount()); storeTeam.recharge(prepayRequest.prepayAmount()); +======= + if (!team.getTeamLeader().getUser_id().equals(user.getUserId())) { + return Message.builder() + .message("팀의 리더가 아닌 사람은 선결제를 할 수 없습니다.") + .build(); + } + + if (prepayRequest.prepayAmount() > user.getPoint()) { + return Message.builder() + .message("보유하고 있는 금액이 선결제 하려는 금액보다 적습니다.") + .build(); + } + + user.usePoint(prepayRequest.prepayAmount()); + PointTransaction pointTransaction = PointTransaction + .builder() + .transactionType(TransactionType.PREPAY) + .transactionedPoint(prepayRequest.prepayAmount()) + .user(user) + .store(store) + .build(); + + pointTransactionRepository.save(pointTransaction); + + StoreTeam buildedStoreTeam = StoreTeam + .builder() + .team(team) + .store(store) + .point(prepayRequest.prepayAmount()) + .personalAllocatedPoint(prepayRequest.personalAllocatedAmount()) + .remainPoint(prepayRequest.prepayAmount()) + .build(); + + Optional storeAndTeam = storeTeamRepository.findByStoreAndTeam(store, team); + + if (storeAndTeam.isEmpty()) { + storeAndTeam = Optional.of(storeTeamRepository.save(buildedStoreTeam)); + } + + StoreTeam storeTeam = storeAndTeam.get(); + storeTeam.recharge(prepayRequest.prepayAmount()); + +>>>>>>> Stashed changes return Message.builder() .message("매장 선결제가 완료되었습니다.") .build(); @@ -104,6 +152,12 @@ public PrepaymentInfoResponse getPrepayInfo(String userId, Long storeId, Long te User user = userRepository.findByProviderId(userId) .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); +<<<<<<< Updated upstream +======= + Team team = teamRepository.findById(teamId) + .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 팀 id 입니다.")); + +>>>>>>> Stashed changes StoreTeam storeTeam = storeTeamRepository.findByStoreIdAndTeamId(storeId, teamId) .orElse(null);