Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 진행중인(대기상태, 요청상태) 포인트 충전, 출금 요청 존재하면 추가 요청 불가 로직 추가 #206

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface PointLogRepository extends JpaRepository<PointLog, Long> {
Page<PointLog> findAllByMember(Member member, Pageable pageable);

List<PointLog> findAllByStatusInOrderByPostTimeDesc(List<PointLog.Status> statuses);

boolean existsByMemberAndStatusIn(Member member, List<PointLog.Status> statuses);
}
15 changes: 13 additions & 2 deletions src/main/java/com/example/sinitto/point/service/PointService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +22,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PointService {

Expand Down Expand Up @@ -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());
}
Expand All @@ -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("시니또의 은행 계좌 정보가 없습니다. 계좌를 등록해야 합니다.");
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down