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

아이템 구매 로직 추가 #63

Merged
merged 13 commits into from
Feb 2, 2025
Merged

아이템 구매 로직 추가 #63

merged 13 commits into from
Feb 2, 2025

Conversation

onegqueen
Copy link

@onegqueen onegqueen commented Dec 27, 2024

🤨 Motivation

🔑 Key Changes

아이템 구매 로직 구현

아직 결제기능 구현에 대한 내용은 미정이지만 두가지 타입으로 구매할 수 있도록 구현해두었습니다.
아이템을 구매하면 구매한 아이템과 잔액정보를 반환하며, 인벤토리에도 구매한 아이템이 추가됩니다.

image

🙏 To Reviewers

  • 구매로직은 생각보다 간단했습니다 ! 몇가지 코멘트 간단히 남겨놨어요

- 아이템들의 각 속성이 달라서 type을 컬럼으로 관리하는 방식에서 join 전략 상속을 통해 관리하도록 수정
ref:#53
- 시즌 한정 아이템은 판매기한으로 구분하도록 수정
ref: #53
- 인벤토리 조회 로직 추가
ref:#53
- credit 생성 및 조회 로직 추가  (button/현금)
ref:#53
- 유저정보 조회시 credit 정보도 함께 조회하도록 수정
ref:#53
@onegqueen onegqueen requested a review from coke98 as a code owner December 27, 2024 07:19
@onegqueen onegqueen self-assigned this Dec 27, 2024
@onegqueen onegqueen added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 27, 2024
@onegqueen onegqueen changed the base branch from main to feature/#53_inventory-domain December 27, 2024 07:20
Copy link
Author

@onegqueen onegqueen left a comment

Choose a reason for hiding this comment

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

구매로직이 생각보다 복잡한건 없어서 간단히 코멘트 남겼습니다 !

@Column(name = "purchase_log_id")
private Long id;

@Column
Copy link
Author

@onegqueen onegqueen Dec 29, 2024

Choose a reason for hiding this comment

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

크레딧 service 단에서 순환참조가 발생하길래 살펴보니
creditService에 구매로그엔티티가 추가되는 로직 이외에는 user를 조회하는 경우는 없는데 구매로그엔티티에서 userEntity를 필드로 가져버리니까 credit도메인에서 user를 참조할 수 밖에 없게 되서 id만 갖도록 수정했습니다.
fetch 타입을 Lazy로 해서 join컬럼의 조회성능문제는 해결하더라도 이런문제가 발생될수 있더라구요,,

Copy link
Contributor

Choose a reason for hiding this comment

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

움 유저 엔티티랑 여기 엔티티랑 순환참조인걸로 이해했는데, 여기서는 양방향 관계가 필요한거죠?

@Transactional
public PurchaseResponse purchaseItem(Long userId, PurchaseRequest request) {
ItemInfo purchasedItem = itemService.addUserItem(userId, request.itemId());
int balance = updateUserCredit(userId, -purchasedItem.price(), request.creditType());
Copy link
Author

Choose a reason for hiding this comment

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

유저 크레딧이 증가되면 양수, 감소하면 음수로 amount를 업데이트 시키는데 코드에 음수가 들어가니 보기가 안좋은거 같긴해서.. 변경타입(입금/출금)을두고 엔티티 내에서 입금이면 +시키고 출금이면 -시키는 편이 좋을까요 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

확실히 파라미터보단 별도 메서드로 만들어주는건 좋은것 같아용

@Transactional
public PurchaseResponse purchaseItem(Long userId, PurchaseRequest request) {
ItemInfo purchasedItem = itemService.addUserItem(userId, request.itemId());
int balance = updateUserCredit(userId, -purchasedItem.price(), request.creditType());
Copy link
Contributor

Choose a reason for hiding this comment

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

확실히 파라미터보단 별도 메서드로 만들어주는건 좋은것 같아용

@Column(name = "purchase_log_id")
private Long id;

@Column
Copy link
Contributor

Choose a reason for hiding this comment

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

움 유저 엔티티랑 여기 엔티티랑 순환참조인걸로 이해했는데, 여기서는 양방향 관계가 필요한거죠?

@coke98 coke98 changed the base branch from feature/#53_inventory-domain to develop February 2, 2025 07:07
@coke98 coke98 merged commit 25cbcd5 into develop Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants