Skip to content

Commit

Permalink
Fix: paymentRecord 중복 처리 transactional 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nampongo committed Apr 16, 2024
1 parent f86262a commit d87b4c2
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
Expand Down Expand Up @@ -93,6 +94,17 @@ public String checkDepositRefundedOrNot(String email, Long myChallengeId) {
return message;
}

@Transactional(isolation = Isolation.SERIALIZABLE)
public void savePaymentRecord(MyChallenge myChallenge, Long memberId, PaymentStatus status) {
checkIfPaymentRecordExist(memberId, myChallenge.getId(), status);
ChallengeGroup group = getGroupById(myChallenge.getChallengeGroupId());
String groupTitle = group.getGroupTitle();
updateGroupParticipantCount(group, status);

PaymentRecord paymentRecord = PaymentRecord.of(status, memberId, myChallenge, groupTitle);
paymentRecordRepository.save(paymentRecord);
}

private void checkIfPaymentRecordExist(Long memberId, Long myChallengeId, PaymentStatus paymentStatus) {
Optional<PaymentRecord> paymentRecords = paymentRecordRepository.findByMemberIdAndMyChallengeIdAndPaymentStatus(memberId, myChallengeId, paymentStatus);
if (paymentRecords.isPresent()) {
Expand All @@ -109,16 +121,6 @@ private void cancelImportPayment(String impUid) {
}
}

private void savePaymentRecord(MyChallenge myChallenge, Long memberId, PaymentStatus status) {
checkIfPaymentRecordExist(memberId, myChallenge.getId(), status);
ChallengeGroup group = getGroupById(myChallenge.getChallengeGroupId());
String groupTitle = group.getGroupTitle();
updateGroupParticipantCount(group, status);

PaymentRecord paymentRecord = PaymentRecord.of(status, memberId, myChallenge, groupTitle);
paymentRecordRepository.save(paymentRecord);
}

private Member getMemberByEmail(String email) {
return memberRepository.findByEmail(email)
.orElseThrow(() -> new MemberNotFoundException("회원 정보를 찾을 수 없습니다."));
Expand Down

0 comments on commit d87b4c2

Please sign in to comment.