-
Notifications
You must be signed in to change notification settings - Fork 3
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: 사용자는 환불 시에 환불액을 주고 받는다 #67
Changes from 4 commits
0f59cde
c0e2864
95f460e
b1675a4
328591b
978538b
584c137
a0bea11
6f16d20
b6f39c9
f0e06d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.wootecam.luckyvickyauction.core.payment.domain; | ||
|
||
import java.util.Optional; | ||
|
||
public interface BidHistoryRepository { | ||
|
||
BidHistory save(BidHistory bidHistory); | ||
|
||
Optional<BidHistory> findById(long bidHistoryId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,14 +34,8 @@ public void process(Member buyer, long price, long auctionId, long quantity) { | |
if (submitBid(price, auctionId, quantity, buyer, seller)) { | ||
Member savedBuyer = memberRepository.save(buyer); | ||
Member savedSeller = memberRepository.save(seller); | ||
BidHistory bidHistory = BidHistory.builder() | ||
.productName(auctionInfo.productName()) | ||
.price(price) | ||
.quantity(quantity) | ||
.bidStatus(BidStatus.BID) | ||
.seller(savedSeller) | ||
.buyer(savedBuyer) | ||
.build(); | ||
BidHistory bidHistory = BidHistory.builder().productName(auctionInfo.productName()).price(price) | ||
.quantity(quantity).bidStatus(BidStatus.BID).seller(savedSeller).buyer(savedBuyer).build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의견: 줄 구분이 있으면 좋을것 같아요! |
||
bidHistoryRepository.save(bidHistory); | ||
} | ||
} | ||
|
@@ -61,4 +55,40 @@ private boolean submitBid(long price, long auctionId, long quantity, Member buye | |
return false; | ||
} | ||
} | ||
|
||
/** | ||
* 구매자는 자신의 입찰 내역에서 상품을 환불할 수 있다 <br> 1. 환불을 요청한 사용자가 구매자 권한이 맞는 지 확인한다 <br> 2. 환불할 입찰 내역의 구매자가 환불을 요청한 사용자인지 확인한다 | ||
* <br> 3. 환불 금액과 수량을 받아와서 교환한다 <br> 4. 경매 서비스에 환불 요청한다 <br> 5. 환불 이후 정보들을 저장한다 | ||
* | ||
* @param buyer 환불을 요청한 사용자 | ||
* @param bidHistoryId 환불할 입찰 내역의 id | ||
*/ | ||
public void refund(Member buyer, long bidHistoryId) { | ||
if (!buyer.isBuyer()) { | ||
throw new BadRequestException("구매자만 환불을 할 수 있습니다.", ErrorCode.P000); | ||
} | ||
|
||
BidHistory refundTargetBidHistory = findRefundTargetBidHistory(bidHistoryId); | ||
Member refundTargetBuyer = refundTargetBidHistory.getBuyer(); | ||
if (buyer.equals(refundTargetBuyer)) { | ||
throw new BadRequestException("환불할 입찰 내역의 구매자만 환불을 할 수 있습니다.", ErrorCode.P003); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의견: equals도 좋지만 BidHistory memberId만 넘겨주어 비교하는 메소드를 만들어줘도 좋을것 같아요! |
||
} | ||
|
||
long price = refundTargetBidHistory.getPrice(); | ||
long quantity = refundTargetBidHistory.getQuantity(); | ||
|
||
Member seller = refundTargetBidHistory.getSeller(); | ||
buyer.chargePoint(price * quantity); | ||
seller.usePoint(price * quantity); | ||
|
||
Member savedBuyer = memberRepository.save(buyer); | ||
Member savedSeller = memberRepository.save(seller); | ||
// TODO 경매 서비스에 환불 요청 | ||
// TODO 환불 요청에 대한 BidHistory 저장 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제안: BidHistory에 bidStatus 필드가 있어서 status를 변경하고 저장하는 로직을 두면 환불 요청에 대한 BidHistory를 저장할 수 있을것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의견: 경매 서비스 환불 요청 인터페이스가 없다면 임의로 만들어도 괜찮지 않을까요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니당~ 포인트 수정 이후에 예외가 발생하는 경우 사용할 방어 로직도 나중에 넣어야겠네요! |
||
} | ||
|
||
private BidHistory findRefundTargetBidHistory(long bidHistoryId) { | ||
return bidHistoryRepository.findById(bidHistoryId).orElseThrow( | ||
() -> new NotFoundException("환불할 입찰 내역을 찾을 수 없습니다. 내역 id=" + bidHistoryId, ErrorCode.P002)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조심스럽게 제안해봅니다. ㅎㅎ