From 51d2fde722c717b882dfc20d10d8bab988fa19b6 Mon Sep 17 00:00:00 2001 From: Seonghun Jeong Date: Fri, 8 Nov 2024 23:19:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=84=ED=96=89=EC=A4=91=EC=9D=B8(?= =?UTF-8?q?=EB=8C=80=EA=B8=B0=EC=83=81=ED=83=9C,=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=83=81=ED=83=9C)=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=B6=A9?= =?UTF-8?q?=EC=A0=84,=20=EC=B6=9C=EA=B8=88=20=EC=A1=B4=EC=9E=AC=EC=8B=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EC=9A=94=EC=B2=AD=20=EB=B6=88=EA=B0=80?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/repository/PointLogRepository.java | 2 ++ .../sinitto/point/service/PointService.java | 15 +++++++++++++-- .../sinitto/point/service/PointServiceTest.java | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/sinitto/point/repository/PointLogRepository.java b/src/main/java/com/example/sinitto/point/repository/PointLogRepository.java index 665e0fc5..e2baff19 100644 --- a/src/main/java/com/example/sinitto/point/repository/PointLogRepository.java +++ b/src/main/java/com/example/sinitto/point/repository/PointLogRepository.java @@ -13,4 +13,6 @@ public interface PointLogRepository extends JpaRepository { Page findAllByMember(Member member, Pageable pageable); List findAllByStatusInOrderByPostTimeDesc(List statuses); + + boolean existsByMemberAndStatusIn(Member member, List statuses); } diff --git a/src/main/java/com/example/sinitto/point/service/PointService.java b/src/main/java/com/example/sinitto/point/service/PointService.java index 53ef6ce5..02e674f6 100644 --- a/src/main/java/com/example/sinitto/point/service/PointService.java +++ b/src/main/java/com/example/sinitto/point/service/PointService.java @@ -1,6 +1,7 @@ package com.example.sinitto.point.service; import com.example.sinitto.common.exception.BadRequestException; +import com.example.sinitto.common.exception.ConflictException; import com.example.sinitto.common.exception.ForbiddenException; import com.example.sinitto.common.exception.NotFoundException; import com.example.sinitto.common.service.KakaoMessageService; @@ -21,6 +22,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service public class PointService { @@ -73,13 +76,17 @@ public PointChargeResponse savePointChargeRequest(Long memberId, int price) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new NotFoundException("요청한 멤버를 찾을 수 없습니다")); + if (pointLogRepository.existsByMemberAndStatusIn(member, List.of(PointLog.Status.CHARGE_REQUEST, PointLog.Status.CHARGE_WAITING))) { + throw new ConflictException("이미 진행중인 포인트 충전 요청이 존재합니다."); + } + pointLogRepository.save(new PointLog(PointLog.Content.CHARGE_REQUEST.getMessage(), member, price, PointLog.Status.CHARGE_REQUEST)); kakaoMessageService.sendPointChargeRequestReceivedMessage(member.getEmail(), price, member.getName(), member.getDepositMessage()); String title = "포인트 충전 요청"; String description = String.format("%s님이 %d 포인트를 충전 요청했습니다.", member.getName(), price); - slackMessageService.sendStyledSlackMessage(title, description,"충전"); + slackMessageService.sendStyledSlackMessage(title, description, "충전"); return new PointChargeResponse(member.getDepositMessage()); } @@ -94,6 +101,10 @@ public void savePointWithdrawRequest(Long memberId, int price) { throw new ForbiddenException("출금 요청은 시니또만 가능합니다. 지금 요청은 시니또가 요청하지 않았습니다."); } + if (pointLogRepository.existsByMemberAndStatusIn(member, List.of(PointLog.Status.WITHDRAW_REQUEST, PointLog.Status.WITHDRAW_WAITING))) { + throw new ConflictException("이미 진행중인 포인트 출금 요청이 존재합니다."); + } + if (!sinittoBankInfoRepository.existsByMemberId(memberId)) { throw new NotFoundException("시니또의 은행 계좌 정보가 없습니다. 계좌를 등록해야 합니다."); } @@ -115,7 +126,7 @@ public void savePointWithdrawRequest(Long memberId, int price) { String title = "포인트 출금 요청"; String description = String.format("%s님이 %d 포인트를 출금 요청했습니다.\n은행: %s, 계좌번호: %s", member.getName(), price, sinittoBankInfo.getBankName(), sinittoBankInfo.getAccountNumber()); - slackMessageService.sendStyledSlackMessage(title, description,"출금"); + slackMessageService.sendStyledSlackMessage(title, description, "출금"); } @Transactional diff --git a/src/test/java/com/example/sinitto/point/service/PointServiceTest.java b/src/test/java/com/example/sinitto/point/service/PointServiceTest.java index e73e7d10..92ea3db4 100644 --- a/src/test/java/com/example/sinitto/point/service/PointServiceTest.java +++ b/src/test/java/com/example/sinitto/point/service/PointServiceTest.java @@ -1,6 +1,7 @@ package com.example.sinitto.point.service; import com.example.sinitto.common.exception.BadRequestException; +import com.example.sinitto.common.exception.ConflictException; import com.example.sinitto.common.exception.ForbiddenException; import com.example.sinitto.common.exception.NotFoundException; import com.example.sinitto.common.service.KakaoMessageService; @@ -163,6 +164,18 @@ void savePointChargeRequest2() { //when then assertThrows(NotFoundException.class, () -> pointService.savePointChargeRequest(1L, 10000)); } + + @Test + @DisplayName("REQUEST or WAITING 상태인 포인트 충전 요청이 있으면 예외를 발생시킨다.") + void savePointChargeRequest3() { + //given + Member member = mock(Member.class); + when(memberRepository.findById(1L)).thenReturn(Optional.of(member)); + when(pointLogRepository.existsByMemberAndStatusIn(member, List.of(PointLog.Status.CHARGE_REQUEST, PointLog.Status.CHARGE_WAITING))).thenReturn(true); + + //when then + assertThrows(ConflictException.class, () -> pointService.savePointChargeRequest(1L, 10000)); + } } @Nested