-
Notifications
You must be signed in to change notification settings - Fork 5
[REFACTOR] - 쿼리 최적화 (N+1 문제를 해결), 빌드 에러 해결 #80
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
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c1f8dac
Merge pull request #4 from TaskSprints/develop
na0th a6a4ec9
fix : Build 에러 수정 및 log 레벨 수정
na0th 801059c
delete : viewCount 삭제
na0th 54dd042
feat : SearchCondition Resolver에 유효 값 검증 추가
na0th 7950838
refactor : Wallet ID 타입 변경(String -> Long)
na0th d3ffce0
refactor : 쿼리 최적화 (N+1 문제) 해결
na0th 8f5f738
refactor : 결제 임시 값 저장 Session -> Redis 리팩터링
na0th 4d8b566
feat : Auction 시작, 종료 시각이 되면 경매 상태가 변경된다.
na0th 19d910f
refactor : 결제 시 JWT 토큰에서 userId 추출
na0th 88a956a
fix : PaymentController 인증/인가 테스트 오류 수정
na0th d1c204f
refactor : 최고 입찰 시, Auction의 highestBid를 갱신한다
na0th 109d19c
feat : 입찰 시 지갑 잔액 검증 추가
na0th 3732f0f
refactor : 서비스에서 지갑 잔액 체크 로직을 도메인 모델로 이동
na0th 8cbcf03
feat : Auction 종료 시 closed_at 생성
na0th e61fba6
feat : 낙찰 시 지갑 잔액 차감 비동기 이벤트 처리
na0th 92f85b3
Merge pull request #5 from na0th/낙찰
na0th b10e418
fix : 입찰 시 Auction 수정 후 save() 누락해서 추가
na0th b6c92c5
refactor : 메서드 가독성을 위한 포맷팅
na0th 4ba03c0
fix : 메서드 리팩터링 시 테스트 오류 해결
na0th 4a04ef6
delete : highestBid, highestBidderId 삭제
na0th db378fb
refactor : initializer, auctionJob 수정
na0th 842fc9f
fix : user 생성 시 wallet 생성 안되던 오류 해결
na0th 6d88c12
Merge branch 'develop' into auction_product
na0th File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...main/java/com/tasksprints/auction/auction/application/service/AuctionScheduleService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.tasksprints.auction.auction.application.service; | ||
|
|
||
| import com.tasksprints.auction.common.jobrunr.AuctionJob; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.jobrunr.scheduling.JobScheduler; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.LocalDateTime; | ||
| import java.time.ZoneId; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class AuctionScheduleService { | ||
| private final JobScheduler jobScheduler; | ||
| private final AuctionJob auctionJob; | ||
|
|
||
| // 작업 ID 관리 (수정/삭제 지원) | ||
| private final Map<Long, UUID> startJobMap = new ConcurrentHashMap<>(); | ||
| private final Map<Long, UUID> endJobMap = new ConcurrentHashMap<>(); | ||
|
|
||
| // 시작 시각 작업 스케줄 | ||
| public void scheduleStart(Long auctionId, LocalDateTime startTime) { | ||
| if (startJobMap.containsKey(auctionId)) { | ||
| UUID jobId = startJobMap.get(auctionId); | ||
| jobScheduler.delete(jobId); // 기존 작업 삭제 | ||
| } | ||
| UUID jobId = jobScheduler.schedule( | ||
| Instant.from(startTime.atZone(ZoneId.systemDefault())), | ||
| () -> auctionJob.startAuction(auctionId) | ||
| ).asUUID(); | ||
|
|
||
| startJobMap.put(auctionId, jobId); | ||
| System.out.println("경매 시작 작업 등록 완료 - ID: " + auctionId + ", 시간: " + startTime); | ||
| } | ||
|
|
||
| // 종료 시각 작업 스케줄 | ||
| public void scheduleEnd(Long auctionId, LocalDateTime endTime) { | ||
|
|
||
| if (endJobMap.containsKey(auctionId)) { | ||
| UUID jobId = endJobMap.get(auctionId); | ||
| jobScheduler.delete(jobId); // 기존 작업 삭제 | ||
| } | ||
| UUID jobId = jobScheduler.schedule( | ||
| Instant.from(endTime.atZone(ZoneId.systemDefault())), | ||
| () -> auctionJob.endAuction(auctionId) | ||
| ).asUUID(); | ||
|
|
||
| endJobMap.put(auctionId, jobId); | ||
| System.out.println("경매 종료 작업 등록 완료 - ID: " + auctionId + ", 시간: " + endTime); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/tasksprints/auction/auction/domain/event/AuctionClosedEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.tasksprints.auction.auction.domain.event; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class AuctionClosedEvent { | ||
| private final Long auctionId; | ||
| private final Long highestBidderId; | ||
| private final BigDecimal highestBidAmount; | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/tasksprints/auction/auction/domain/event/AuctionClosedEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.tasksprints.auction.auction.domain.event; | ||
|
|
||
| import com.tasksprints.auction.wallet.domain.entity.Wallet; | ||
| import com.tasksprints.auction.wallet.infrastructure.WalletRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AuctionClosedEventListener { | ||
| private final WalletRepository walletRepository; | ||
|
|
||
| /** | ||
| * 비동기로 지갑 잔액 차감 처리 | ||
| * 동기로 처리하게 되면 이벤트 처리 할 때까지 경매의 close 상태를 업데이트 커밋하지 않음(트랜잭션 커밋) | ||
| * 경매를 닫고(트랜잭션 끝내고), 비동기로 잔액 차감을 처리해도 문제 없다.. | ||
| */ | ||
| @Async("asyncExecutor") | ||
| @EventListener | ||
| @Transactional | ||
| public void handleAuctionClosed(AuctionClosedEvent event) { | ||
| log.info("경매 종료 이벤트 처리: auctionId={}", event.getAuctionId()); | ||
| try { | ||
| Wallet winnerWallet = walletRepository.getWalletByUserId(event.getHighestBidderId()); | ||
| winnerWallet.deductBalance(event.getHighestBidAmount()); | ||
| walletRepository.save(winnerWallet); | ||
| log.info("지갑 잔액 차감 성공: auctionId={}", event.getAuctionId()); | ||
| } catch (Exception e) { | ||
| log.error("지갑 잔액 차감 실패: auctionId={}, error={}", event.getAuctionId(), e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/tasksprints/auction/auction/exception/InvalidAuctionStateException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.tasksprints.auction.auction.exception; | ||
|
|
||
| public class InvalidAuctionStateException extends RuntimeException { | ||
| public InvalidAuctionStateException(String message) { | ||
| super(message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.