Skip to content

Commit

Permalink
Merge pull request #178 from 9oormthon-univ/feat/prepay
Browse files Browse the repository at this point in the history
Feat/prepay
  • Loading branch information
HyunWoo9930 authored Nov 28, 2024
2 parents 50abb14 + 3e66ed2 commit 567e3a8
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<StoreTeam> 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();
Expand All @@ -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);

Expand Down

0 comments on commit 567e3a8

Please sign in to comment.