-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Feat/#89 lock #92
Conversation
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.
์๊ณ ํ์
จ์ต๋๋ค!
๊ทผ๋ฐ ํน์ ํฐ์ผ ์ทจ์ํ ๋๋ lock์ ๊ฑธ์ด์ผ ํ ๊น์??
์ค ๊ทธ๊ฑด ์๊ฐ๋ชปํ๋ค์ ์ทจ์ํ ๋๋ lock์ ์ฉํ์์ฃ ! |
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.
๋ฝ ๊ตฌํํ๊ณ ์ง์ ํ
์คํธํ๋๋ฐ ์ด๋ ค์ ์ ํ
๋ฐ ์ ์ ์ฉํ์ ๊ฒ ๊ฐ๋ค์!
์ง๋ฌธ ๋ช๊ฐ ๋จ๊ฒจ๋ด
๋๋ค..!
.orElseThrow(() -> new GeneralException(ErrorStatus.PERFORMANCE_NOT_FOUND)); | ||
} catch (PessimisticLockException e) { | ||
log.error("๊ณต์ฐ ๋ฝ ํ๋ ์คํจ, ๊ณต์ฐ ID: " + email); | ||
throw e; |
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.
throw e๋ฅผ ํ๊ฒ๋๋ฉด ์ผ๋ฐ ์๋ฌ๊ฐ ๋ฐ์ํ๋๊ฑด๊ฐ์?
์ปค์คํ
์๋ฌ๋ก ์ฒ๋ฆฌํ๊ฑฐ๋, ๋ฉ์ธ์ง๋ฅผ ๋ด์์ ์คํ๋ง์์ ์ ๊ณตํด์ฃผ๋ ์์ธ๋ก ๋์ง๋ ๊ฒ์ด ์์ธ ์ฒ๋ฆฌ ๋ฐ ๋๋ฒ๊น
ํ ๋ ์ฉ์ดํ ๊ฒ ๊ฐ์ต๋๋ค!
@@ -83,21 +87,52 @@ public TicketResponseDto getTicketByEmailAndTicketId(String email, Long ticketId | |||
@Override | |||
@Transactional | |||
public TicketResponseDto registerTicket(String email, TicketRequestDto ticketRequest) { |
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.
ํฐ์ผ์ ๋ฑ๋กํ ๋ ์ฝ๋์ ์ฑ
์์ ๋ช
ํํ ํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
๊ฐ์ฒด์งํฅ ์์น์ค์ ๋จ์ผ์ฑ
์ ์์น์ ๊ณ ๋ คํด๋ณด์๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์!
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.
์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค! ๋ถ๋ฆฌํ๋๋ก ํ๊ฒ ์ต๋๋ค!
PerformanceEntity performanceEntity = findPerformanceById(ticketRequest.performanceId()); | ||
log.info("๊ณต์ฐ์ ๋ํ ๋ฝ์ ํ๋ ์๋ ์ค, ๊ณต์ฐ ID: " + email); | ||
|
||
PerformanceEntity performanceEntity; |
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.
performance๋ฅผ ๋ถ๋ฌ์ค๋๊ฒ์ ํ๋์ ํจ์๋ก ๋ถ๋ฆฌ์ํค๋๊ฒ ์ด๋จ๊น์?
ํ์ค๋ก ๋๋๋ ๊ฒ๋ ์๋๊ณ , try-catch๋ฌธ๊น์ง ์์ด์ ๋ฝ์ ๊ฐ์ง ๊ณต์ฐ์ ๋ถ๋ฌ์จ๋ค <- ์ด ์ฑ
์์ ๊ฐ์ง ํจ์๋ฅผ ํ๋ ์์ฑํ๋ ๊ฒ์ด ์ด๋จ๊น ์ถ์ต๋๋ค.
|
||
log.info("๊ณต์ฐ ๋ฝ ํ๋ ์๋ฃ, ๊ณต์ฐ ID: " + email); | ||
|
||
if (performanceEntity.getRemainingTickets() < ticketRequest.quantity()) { |
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.
์ด ๋ถ๋ถ๋ ๊ณต์ฐ์ ํฐ์ผ์ ์๊ฐ ์ ํจํ์ง ํ์ธํ๋ ๋ถ๋ถ์ด๋ผ validate ๊ด๋ จ ๋ค์ด๋ฐ์ ๊ฐ์ง ํจ์๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ข์๋ณด์ ๋๋ค!
log.warn("๋จ์ ํฐ์ผ ์ ๋ถ์กฑ, ๊ณต์ฐ ID: " + ticketRequest.performanceId()); | ||
throw new GeneralException(ErrorStatus._NOT_ENOUGH_TICKETS); | ||
} | ||
//๋น๊ด์ ๋ฝ์ด ๊ฑธ๋ฆฐ ํ์ ๋๊ธฐ ์๊ฐ ์ถ๊ฐ (์๊ฐ์ ์ผ๋ก ํ์ธํ๊ธฐ ์ํจ) |
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.
์ฃผ์์ ์ฝ๋์ ๊ฐ๋ ์ฑ์ ํด์น๊ฒ ๋๋ ์ ๊ฑฐ ๋ถํ๋๋ฆฝ๋๋ค..!
int finalPrice = calculateFinalPrice(performanceEntity.getPrice(), ticketRequest.quantity(), ticketRequest.couponId()); | ||
|
||
// ํฐ์ผ ์์ฑ ๋ฐ ์ ์ฅ | ||
TicketEntity ticketEntity = createAndSaveTicket(memberEntity, performanceEntity, ticketRequest.quantity(), finalPrice); | ||
|
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.
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); |
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.
@slf4j๋ฅผ ์ฌ์ฉํด๋ณด์๋๊ฑด ์ด๋ ์ ๊ฐ์?
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.
๊ณ ์ํ์ จ์ต๋๋ค~!
๐ ๊ณผ์ ์ค๋ช
๐ฉโ๐ป ์๊ตฌ ์ฌํญ๊ณผ ๊ตฌํ ๋ด์ฉ
[feat] : ํฐ์ผ ๊ตฌ๋งค ์๋ฃ์ ๊ตฌ๋งค์๋๋งํผ ๋จ์ํฐ์ผ์๋ ๊ฐ์ ๊ตฌํ
[feat] : ๋จ์ ํฐ์ผ์ด ๊ตฌ๋งค๋ฅผ ํฌ๋งํ๋ ํฐ์ผ๋ณด๋ค ์ ์๊ฒฝ์ฐ ์์ธ์ฒ๋ฆฌ ๊ตฌํ
[feat] : ๋น๊ด์ ๋ฝ x Lock์ ์ด์ฉํด ๋์์ฑ ์ ์ด ๊ตฌํ
โ ํผ๋๋ฐฑ ๋ฐ์์ฌํญ
โ PR ํฌ์ธํธ & ๊ถ๊ธํ ์
https://moon99610.tistory.com/66
->์์ธํ ์ค๋ช ์ ์ฌ๊ธฐ์ ๊ธฐ๋กํด๋์์ต๋๋ค!