Skip to content

Conversation

@PicturePark1101
Copy link
Contributor

@PicturePark1101 PicturePark1101 commented Apr 30, 2025

작업내용

구매 연필 사용 시 PurchasedPencil에도 반영되도록 fix

상세설명_ & 캡쳐

  • PurchasedPencil에서 member가 일치하고 remainQuantity가 0 초과인 것들을 createdAt 오름차순으로 가져옴
	@Query("select p from PurchasedPencil p where p.member = :member and p.remainQuantity > :remainQuantity order by p.createdAt asc")
	List<PurchasedPencil> findByMemberAndRemainQuantityGreaterThanOrderByCreatedAtAsc(@Param("member") Member buyer,
		@Param("remainQuantity") Long remainQuantity);

기존 코드에 메소드 추가

-구매 연필 사용 시. consumePurchasedPencils 메소드 호출

public void executePayment(Member buyer, PencilAccount buyerAccount, PencilAccount sellerAccount, Long price) {
		long acquiredUsed = Math.min(buyerAccount.getAcquiredBalance(), price);
		buyerAccount.decreaseAcquiredBalance(acquiredUsed);

		long unpaidPencil = price - acquiredUsed;
		if (unpaidPencil > 0) {
			if (buyerAccount.getPurchasedBalance() < unpaidPencil) {
				throw new SharedNoteHandler(ErrorStatus.SHAREDNOTE_NOT_ENOUGH_PENCIL);
			}
			**consumePurchasedPencils(buyer, unpaidPencil);**
			buyerAccount.decreasePurchasedBalance(unpaidPencil);
		}

		sellerAccount.increaseAcquiredBalance(price);
	}

전체메소드

  • list 돌려 순차적으로 remainQuantity 차감
	private void consumePurchasedPencils(Member buyer, long unpaidPencil) {
		List<PurchasedPencil> purchasedPencils = purchasedPencilUpdater.findByMemberAndRemainQuantityGreaterThanOrderByCreatedAtAsc(
			buyer, 0L);

		long remainingToConsume = unpaidPencil;

		for (PurchasedPencil purchasedPencil : purchasedPencils) {
			if (remainingToConsume == 0)
				break;

			long available = purchasedPencil.getRemainQuantity();
			long toConsume = Math.min(available, remainingToConsume);

			purchasedPencil.decreaseRemainQuantity(toConsume); // remainQuantity -= toConsume
			remainingToConsume -= toConsume;
		}

		if (remainingToConsume > 0) {
			throw new SharedNoteHandler(ErrorStatus.SHAREDNOTE_NOT_ENOUGH_PENCIL);
		}
	}

@PicturePark1101 PicturePark1101 self-assigned this Apr 30, 2025
@PicturePark1101 PicturePark1101 added 진이 작업했습니다. 👊🏻 PULL REQUEST pr날릴때 🐞 bugFix 버그 고침 labels Apr 30, 2025
break;

long available = purchasedPencil.getRemainQuantity();
long toConsume = Math.min(available, remainingToConsume);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.min 을 통해서, 요구하는 부분을 쉽게 나타내시는 거 같아요!! 좋은 코드 같습니다,!!

}

private void consumePurchasedPencils(Member buyer, long unpaidPencil) {
List<PurchasedPencil> purchasedPencils = purchasedPencilUpdater.findByMemberAndRemainQuantityGreaterThanOrderByCreatedAtAsc(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분에
DELIVERY_SUCCESS(0), //The app delivered the consumable in-app purchase and it’s working properly.
Purchased_ Pencill 부분에 DELIVERY STATUS 라는 컬럼이 존재하는 데, DELIVERY SUCCESS 인 경우에만 해당 작업이 진행되어야 하므로, 해당 where 절에 추가 되어야 할 듯 합니다.
제가 미리 말씀 드렸어야 하는 데 죄송합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아닙니다 추가하겠습니다 👍 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 DELIVERY STATUS은 Integer로 저장되는건가요?? 코드상에선 그런 것 같아 여쭤봅니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 DELIVERY STATUS은 Integer로 저장되는건가요?? 코드상에선 그런 것 같아 여쭤봅니다!

넵 맞습니다!! 감사합니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

머지 하셔도 될 듯 합니다!!

@PicturePark1101 PicturePark1101 merged commit 3b1efec into dev May 11, 2025
1 check passed
@PicturePark1101 PicturePark1101 deleted the fix/#357 branch May 11, 2025 09:11
PicturePark1101 added a commit that referenced this pull request Jun 1, 2025
[fix/#357] 구매 연필 사용 시 PurchasedPencil에도 반영되도록 fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

진이 작업했습니다. 🐞 bugFix 버그 고침 👊🏻 PULL REQUEST pr날릴때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants