Skip to content

Commit

Permalink
feat : 선결제시 1인 사용 금액 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 28, 2024
1 parent 86dbea0 commit 1c6c2bd
Showing 1 changed file with 0 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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 @@ -50,7 +47,6 @@ 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 @@ -99,49 +95,7 @@ public Message prepay(String userId, PrepayRequest prepayRequest) {
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 @@ -152,12 +106,6 @@ 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 1c6c2bd

Please sign in to comment.