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/#89 lock #92

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Feat/#89 lock #92

wants to merge 5 commits into from

Conversation

sunghyun0610
Copy link
Collaborator

@sunghyun0610 sunghyun0610 commented Oct 25, 2024

๐Ÿ“Œ ๊ณผ์ œ ์„ค๋ช…

๐Ÿ‘ฉโ€๐Ÿ’ป ์š”๊ตฌ ์‚ฌํ•ญ๊ณผ ๊ตฌํ˜„ ๋‚ด์šฉ

[feat] : ํ‹ฐ์ผ“ ๊ตฌ๋งค ์™„๋ฃŒ์‹œ ๊ตฌ๋งค์ˆ˜๋Ÿ‰๋งŒํผ ๋‚จ์€ํ‹ฐ์ผ“์ˆ˜๋Ÿ‰ ๊ฐ์†Œ ๊ตฌํ˜„
[feat] : ๋‚จ์€ ํ‹ฐ์ผ“์ด ๊ตฌ๋งค๋ฅผ ํฌ๋งํ•˜๋Š” ํ‹ฐ์ผ“๋ณด๋‹ค ์ ์€๊ฒฝ์šฐ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๊ตฌํ˜„
[feat] : ๋น„๊ด€์  ๋ฝ x Lock์„ ์ด์šฉํ•ด ๋™์‹œ์„ฑ ์ œ์–ด ๊ตฌํ˜„

โœ… ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜์‚ฌํ•ญ

โœ… PR ํฌ์ธํŠธ & ๊ถ๊ธˆํ•œ ์ 

https://moon99610.tistory.com/66
->์ž์„ธํ•œ ์„ค๋ช…์€ ์—ฌ๊ธฐ์— ๊ธฐ๋กํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค!

Copy link
Collaborator

@yeonsu00 yeonsu00 left a comment

Choose a reason for hiding this comment

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

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!
๊ทผ๋ฐ ํ˜น์‹œ ํ‹ฐ์ผ“ ์ทจ์†Œํ•  ๋•Œ๋„ lock์„ ๊ฑธ์–ด์•ผ ํ• ๊นŒ์š”??

@sunghyun0610
Copy link
Collaborator Author

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค! ๊ทผ๋ฐ ํ˜น์‹œ ํ‹ฐ์ผ“ ์ทจ์†Œํ•  ๋•Œ๋„ lock์„ ๊ฑธ์–ด์•ผ ํ• ๊นŒ์š”??

์˜ค ๊ทธ๊ฑด ์ƒ๊ฐ๋ชปํ–ˆ๋„ค์š” ์ทจ์†Œํ• ๋•Œ๋„ lock์ ์šฉํ•˜์‹œ์ฃ !

Copy link
Collaborator

@Icecoff22 Icecoff22 left a comment

Choose a reason for hiding this comment

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

๋ฝ ๊ตฌํ˜„ํ•˜๊ณ  ์ง์ ‘ ํ…Œ์ŠคํŠธํ•˜๋Š”๋ฐ ์–ด๋ ค์› ์„ ํ…๋ฐ ์ž˜ ์ ์šฉํ•˜์‹  ๊ฒƒ ๊ฐ™๋„ค์š”!
์งˆ๋ฌธ ๋ช‡๊ฐœ ๋‚จ๊ฒจ๋ด…๋‹ˆ๋‹ค..!

.orElseThrow(() -> new GeneralException(ErrorStatus.PERFORMANCE_NOT_FOUND));
} catch (PessimisticLockException e) {
log.error("๊ณต์—ฐ ๋ฝ ํš๋“ ์‹คํŒจ, ๊ณต์—ฐ ID: " + email);
throw e;
Copy link
Collaborator

Choose a reason for hiding this comment

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

throw e๋ฅผ ํ•˜๊ฒŒ๋˜๋ฉด ์ผ๋ฐ˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๊ฑด๊ฐ€์š”?
์ปค์Šคํ…€ ์—๋Ÿฌ๋กœ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜, ๋ฉ”์„ธ์ง€๋ฅผ ๋‹ด์•„์„œ ์Šคํ”„๋ง์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ์˜ˆ์™ธ๋กœ ๋˜์ง€๋Š” ๊ฒƒ์ด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐ ๋””๋ฒ„๊น…ํ•  ๋•Œ ์šฉ์ดํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

@@ -83,21 +87,52 @@ public TicketResponseDto getTicketByEmailAndTicketId(String email, Long ticketId
@Override
@Transactional
public TicketResponseDto registerTicket(String email, TicketRequestDto ticketRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํ‹ฐ์ผ“์„ ๋“ฑ๋กํ•  ๋•Œ ์ฝ”๋“œ์˜ ์ฑ…์ž„์„ ๋ช…ํ™•ํžˆ ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
๊ฐ์ฒด์ง€ํ–ฅ ์›์น™์ค‘์— ๋‹จ์ผ์ฑ…์ž„ ์›์น™์„ ๊ณ ๋ คํ•ด๋ณด์‹œ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์ข‹์€ ํ”ผ๋“œ๋ฐฑ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋ถ„๋ฆฌํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

PerformanceEntity performanceEntity = findPerformanceById(ticketRequest.performanceId());
log.info("๊ณต์—ฐ์— ๋Œ€ํ•œ ๋ฝ์„ ํš๋“ ์‹œ๋„ ์ค‘, ๊ณต์—ฐ ID: " + email);

PerformanceEntity performanceEntity;
Copy link
Collaborator

Choose a reason for hiding this comment

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

performance๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š”๊ฒƒ์„ ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋กœ ๋ถ„๋ฆฌ์‹œํ‚ค๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?
ํ•œ์ค„๋กœ ๋๋‚˜๋Š” ๊ฒƒ๋„ ์•„๋‹ˆ๊ณ , try-catch๋ฌธ๊นŒ์ง€ ์žˆ์–ด์„œ ๋ฝ์„ ๊ฐ€์ง„ ๊ณต์—ฐ์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค <- ์ด ์ฑ…์ž„์„ ๊ฐ€์ง„ ํ•จ์ˆ˜๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์–ด๋–จ๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค.


log.info("๊ณต์—ฐ ๋ฝ ํš๋“ ์™„๋ฃŒ, ๊ณต์—ฐ ID: " + email);

if (performanceEntity.getRemainingTickets() < ticketRequest.quantity()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ด ๋ถ€๋ถ„๋„ ๊ณต์—ฐ์˜ ํ‹ฐ์ผ“์˜ ์ˆ˜๊ฐ€ ์œ ํšจํ•œ์ง€ ํ™•์ธํ•˜๋Š” ๋ถ€๋ถ„์ด๋ผ validate ๊ด€๋ จ ๋„ค์ด๋ฐ์„ ๊ฐ€์ง„ ํ•จ์ˆ˜๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค!

log.warn("๋‚จ์€ ํ‹ฐ์ผ“ ์ˆ˜ ๋ถ€์กฑ, ๊ณต์—ฐ ID: " + ticketRequest.performanceId());
throw new GeneralException(ErrorStatus._NOT_ENOUGH_TICKETS);
}
//๋น„๊ด€์  ๋ฝ์ด ๊ฑธ๋ฆฐ ํ›„์— ๋Œ€๊ธฐ ์‹œ๊ฐ„ ์ถ”๊ฐ€ (์‹œ๊ฐ์ ์œผ๋กœ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•จ)
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ฃผ์„์€ ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ํ•ด์น˜๊ฒŒ ๋˜๋‹ˆ ์ œ๊ฑฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค..!

int finalPrice = calculateFinalPrice(performanceEntity.getPrice(), ticketRequest.quantity(), ticketRequest.couponId());

// ํ‹ฐ์ผ“ ์ƒ์„ฑ ๋ฐ ์ €์žฅ
TicketEntity ticketEntity = createAndSaveTicket(memberEntity, performanceEntity, ticketRequest.quantity(), finalPrice);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private updateRemainingTickets(PerformanceEntity performanceEntity, int ticketQuantity) {
int remainTicket = performanceEntity.getRemainingTickets() - ticketEntity.getQuantity();
log.info("ํ‹ฐ์ผ“ ๋“ฑ๋ก ํ›„ ๋‚จ์€ ํ‹ฐ์ผ“ ์ˆ˜๋Ÿ‰: " + remainTicket);
performanceEntity.updateTicket(remainTicket);
log.info("๊ณต์—ฐ ํ…Œ์ด๋ธ”์˜ ๋‚จ์€ ํ‹ฐ์ผ“ ์ˆ˜ ์—…๋ฐ์ดํŠธ ์™„๋ฃŒ: " + performanceEntity.getRemainingTickets());
}

์ด ๋ถ€๋ถ„๋„ ๊ณต์—ฐ์˜ ํ‹ฐ์ผ“์„ ์ˆ˜์ •ํ•œ๋‹ค๋Š” ๊ฐœ๋…์œผ๋กœ ๋”ฐ๋กœ ๋ถ„๋ฆฌ๊ฐ€ ๋˜์–ด์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

@@ -33,10 +37,10 @@
@RequiredArgsConstructor
public class TicketServiceImpl implements TicketService {

private static final Logger log = LoggerFactory.getLogger(TicketServiceImpl.class);
Copy link
Member

Choose a reason for hiding this comment

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

@slf4j๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์‹œ๋Š”๊ฑด ์–ด๋– ์‹ ๊ฐ€์š”?

Copy link
Member

@macmorning0116 macmorning0116 left a comment

Choose a reason for hiding this comment

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

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ํ‹ฐ์ผ“ ๋™์‹œ์„ฑ ์ œ์–ด ๊ธฐ๋Šฅ ๊ตฌํ˜„
4 participants