-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 입금 확인 요청, 승인, 거절 api 추가 및 입금 요청 리스트 조회 api 추가 #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9a08b8
feat: 참여자 정산 확인 요청, 승인, 거절 기능 추가 및 테스트 코드 추가
sudhdkso 4464d37
feat: 참여자 정산 요청 리스트 조회 api 추가 및 테스트 코드 추가
sudhdkso a25a811
feat: 참여자 정산 요청 리스트 조회시 멤버 프로필 컬럼 추가 및 입금 요청에 대한 api 문서 추가
sudhdkso 166c7e4
feat: 참여자 선택 전략 수정 및 PaymentRequest엔티티 일부 수정
sudhdkso 141a8c5
test: 테스트 코드 수정
sudhdkso fd46158
test: 테스트 코드 수정
sudhdkso 608526f
fix: 참여자 선택 로직 수정
sudhdkso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| = 입금 확인 요청 (PaymentRequest) | ||
| :toc: left | ||
| :toclevels: 2 | ||
|
|
||
| == 입금 확인 요청 목록 조회 | ||
|
|
||
| 로그인한 사용자를 대상으로 들어온 입금 확인 요청 목록을 조회할 수 있습니다. | ||
|
|
||
| === Example | ||
|
|
||
| include::{snippets}/payment-request-controller-test/get-payment-requests/curl-request.adoc[] | ||
|
|
||
| === HTTP | ||
|
|
||
| ==== 요청 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/get-payment-requests/http-request.adoc[] | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/get-payment-requests/http-response.adoc[] | ||
|
|
||
| === Body | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/get-payment-requests/response-body.adoc[] | ||
|
|
||
| == 입금 확인 요청 생성 | ||
|
|
||
| 정산 참여자가 총무에게 입금 확인 요청을 보낼 수 있습니다. | ||
|
|
||
| === Example | ||
|
|
||
| include::{snippets}/payment-request-controller-test/create-payment-request/curl-request.adoc[] | ||
|
|
||
| === HTTP | ||
|
|
||
| ==== 요청 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/create-payment-request/http-request.adoc[] | ||
|
|
||
| include::{snippets}/payment-request-controller-test/create-payment-request/path-parameters.adoc[] | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/create-payment-request/http-response.adoc[] | ||
|
|
||
| === Body | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/create-payment-request/response-body.adoc[] | ||
|
|
||
| == 입금 확인 요청 승인 | ||
|
|
||
| 총무가 입금 확인 요청을 승인할 수 있습니다. | ||
|
|
||
| === Example | ||
|
|
||
| include::{snippets}/payment-request-controller-test/approve-payment-request/curl-request.adoc[] | ||
|
|
||
| === HTTP | ||
|
|
||
| ==== 요청 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/approve-payment-request/http-request.adoc[] | ||
|
|
||
| include::{snippets}/payment-request-controller-test/approve-payment-request/path-parameters.adoc[] | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/approve-payment-request/http-response.adoc[] | ||
|
|
||
| === Body | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/approve-payment-request/response-body.adoc[] | ||
|
|
||
| == 입금 확인 요청 거절 | ||
|
|
||
| 총무가 입금 확인 요청을 거절할 수 있습니다. | ||
|
|
||
| === Example | ||
|
|
||
| include::{snippets}/payment-request-controller-test/reject-payment-request/curl-request.adoc[] | ||
|
|
||
| === HTTP | ||
|
|
||
| ==== 요청 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/reject-payment-request/http-request.adoc[] | ||
|
|
||
| include::{snippets}/payment-request-controller-test/reject-payment-request/path-parameters.adoc[] | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/reject-payment-request/http-response.adoc[] | ||
|
|
||
| === Body | ||
|
|
||
| ==== 응답 | ||
|
|
||
| include::{snippets}/payment-request-controller-test/reject-payment-request/response-body.adoc[] |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/dnd/moddo/event/application/command/CommandPaymentRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.dnd.moddo.event.application.command; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import com.dnd.moddo.event.application.impl.PaymentRequestCreator; | ||
| import com.dnd.moddo.event.application.impl.PaymentRequestUpdater; | ||
| import com.dnd.moddo.event.domain.paymentRequest.PaymentRequest; | ||
| import com.dnd.moddo.event.presentation.response.PaymentRequestResponse; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class CommandPaymentRequest { | ||
| private final PaymentRequestCreator paymentRequestCreator; | ||
| private final PaymentRequestUpdater paymentRequestUpdater; | ||
|
|
||
| public PaymentRequestResponse createPaymentRequest(Long settlementId, Long userId) { | ||
| PaymentRequest paymentRequest = paymentRequestCreator.createPaymentRequest(settlementId, userId); | ||
| return PaymentRequestResponse.of(paymentRequest); | ||
| } | ||
|
|
||
| public PaymentRequestResponse approvePaymentRequest(Long paymentRequestId, Long userId) { | ||
| PaymentRequest paymentRequest = paymentRequestUpdater.approvePaymentRequest(paymentRequestId, userId); | ||
| return PaymentRequestResponse.of(paymentRequest); | ||
| } | ||
|
|
||
| public PaymentRequestResponse rejectPaymentRequest(Long paymentRequestId, Long userId) { | ||
| PaymentRequest paymentRequest = paymentRequestUpdater.rejectPaymentRequest(paymentRequestId, userId); | ||
| return PaymentRequestResponse.of(paymentRequest); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/dnd/moddo/event/application/impl/PaymentRequestCreator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.dnd.moddo.event.application.impl; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import com.dnd.moddo.event.domain.member.Member; | ||
| import com.dnd.moddo.event.domain.paymentRequest.PaymentRequest; | ||
| import com.dnd.moddo.event.domain.settlement.Settlement; | ||
| import com.dnd.moddo.event.infrastructure.PaymentRequestRepository; | ||
| import com.dnd.moddo.user.application.impl.UserReader; | ||
| import com.dnd.moddo.user.domain.User; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PaymentRequestCreator { | ||
| private final PaymentRequestRepository paymentRequestRepository; | ||
| private final MemberReader memberReader; | ||
| private final SettlementReader settlementReader; | ||
| private final UserReader userReader; | ||
| private final PaymentRequestValidator paymentRequestValidator; | ||
|
|
||
| public PaymentRequest createPaymentRequest(Long settlementId, Long userId) { | ||
| Member requestMember = memberReader.findBySettlementIdAndUserId(settlementId, userId); | ||
| Settlement settlement = settlementReader.read(settlementId); | ||
|
|
||
| paymentRequestValidator.validateCreateRequest(settlementId, requestMember); | ||
|
|
||
| User targetUser = userReader.read(settlement.getWriter()); | ||
|
|
||
| PaymentRequest paymentRequest = PaymentRequest.builder() | ||
| .settlement(settlement) | ||
| .requestMember(requestMember) | ||
| .targetUser(targetUser) | ||
| .build(); | ||
|
|
||
| return paymentRequestRepository.save(paymentRequest); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/dnd/moddo/event/application/impl/PaymentRequestReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.dnd.moddo.event.application.impl; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.dnd.moddo.event.domain.member.Member; | ||
| import com.dnd.moddo.event.domain.memberExpense.MemberExpense; | ||
| import com.dnd.moddo.event.domain.paymentRequest.PaymentRequest; | ||
| import com.dnd.moddo.event.domain.paymentRequest.PaymentRequestStatus; | ||
| import com.dnd.moddo.event.infrastructure.PaymentRequestRepository; | ||
| import com.dnd.moddo.event.presentation.response.PaymentRequestItemResponse; | ||
| import com.dnd.moddo.event.presentation.response.PaymentRequestsResponse; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| @RequiredArgsConstructor | ||
| public class PaymentRequestReader { | ||
| private final PaymentRequestRepository paymentRequestRepository; | ||
| private final MemberExpenseReader memberExpenseReader; | ||
|
|
||
| public PaymentRequestsResponse findByTargetUserId(Long targetUserId) { | ||
| List<PaymentRequest> paymentRequests = paymentRequestRepository.findByTargetUserId(targetUserId) | ||
| .stream().filter(paymentRequest -> paymentRequest.getStatus() == PaymentRequestStatus.PENDING) | ||
| .toList(); | ||
|
|
||
| List<Long> memberIds = paymentRequests.stream() | ||
| .map(PaymentRequest::getRequestMemberId) | ||
| .distinct() | ||
| .toList(); | ||
|
|
||
| Map<Long, Long> amountByMemberId = memberExpenseReader.findAllByMemberIds(memberIds).stream() | ||
| .collect(Collectors.groupingBy( | ||
| MemberExpense::getMemberId, | ||
| Collectors.summingLong(me -> me.getAmount() != null ? me.getAmount() : 0L) | ||
| )); | ||
sudhdkso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| List<PaymentRequestItemResponse> responses = paymentRequests.stream() | ||
| .map(paymentRequest -> { | ||
| Member member = paymentRequest.getRequestMember(); | ||
| Long memberId = member.getId(); | ||
|
|
||
| return new PaymentRequestItemResponse( | ||
| paymentRequest.getRequestedAt(), | ||
| paymentRequest.getId(), | ||
| memberId, | ||
| member.getName(), | ||
| member.getProfileUrl(), | ||
| amountByMemberId.getOrDefault(memberId, 0L) | ||
| ); | ||
| }) | ||
| .sorted(Comparator.comparing(PaymentRequestItemResponse::requestedAt).reversed()) | ||
| .toList(); | ||
|
|
||
| return PaymentRequestsResponse.of(responses); | ||
| } | ||
|
|
||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/main/java/com/dnd/moddo/event/application/impl/PaymentRequestUpdater.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.dnd.moddo.event.application.impl; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.dnd.moddo.event.domain.paymentRequest.PaymentRequest; | ||
| import com.dnd.moddo.event.infrastructure.PaymentRequestRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class PaymentRequestUpdater { | ||
| private final PaymentRequestRepository paymentRequestRepository; | ||
| private final PaymentRequestValidator paymentRequestValidator; | ||
| private final MemberUpdater memberUpdater; | ||
|
|
||
| @Transactional | ||
| public PaymentRequest approvePaymentRequest(Long paymentRequestId, Long userId) { | ||
| PaymentRequest paymentRequest = paymentRequestRepository.getById(paymentRequestId); | ||
| paymentRequestValidator.validateProcessRequest(paymentRequest, userId); | ||
| memberUpdater.updatePaymentStatus(paymentRequest.getRequestMemberId(), true); | ||
| paymentRequest.approve(); | ||
| return paymentRequest; | ||
| } | ||
|
|
||
| @Transactional | ||
| public PaymentRequest rejectPaymentRequest(Long paymentRequestId, Long userId) { | ||
| PaymentRequest paymentRequest = paymentRequestRepository.getById(paymentRequestId); | ||
| paymentRequestValidator.validateProcessRequest(paymentRequest, userId); | ||
| paymentRequest.reject(); | ||
| return paymentRequest; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.