File tree Expand file tree Collapse file tree 5 files changed +47
-25
lines changed
src/main/kotlin/gogo/gogobetting/domain/betting/root Expand file tree Collapse file tree 5 files changed +47
-25
lines changed Original file line number Diff line number Diff line change 1+ package gogo.gogobetting.domain.betting.root.application
2+
3+ import gogo.gogobetting.domain.betting.result.persistence.BettingResultRepository
4+ import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleDto
5+ import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleInfoDto
6+ import gogo.gogobetting.domain.betting.root.application.dto.BettingInfoDto
7+ import gogo.gogobetting.domain.betting.root.application.dto.BettingResultInfoDto
8+ import gogo.gogobetting.domain.betting.root.persistence.Betting
9+ import org.springframework.stereotype.Component
10+
11+ @Component
12+ class BettingMapper (
13+ private val bettingResultRepository : BettingResultRepository )
14+ {
15+
16+ fun mapBundle (bettingList : List <Betting >): BettingBundleDto {
17+ val bundleInfo = bettingList.map { betting ->
18+ val bettingInfoDto = BettingInfoDto (betting.id, betting.point, betting.predictedWinTeamId)
19+
20+ val bettingResult = bettingResultRepository.findByBettingIdAndIsCancelled(betting.id)
21+ val bettingResultInfoDto = bettingResult?.let {
22+ BettingResultInfoDto (
23+ isPredicted = bettingResult.isPredicted,
24+ earnedPoint = bettingResult.earnedPoint
25+ )
26+ }
27+
28+ BettingBundleInfoDto (
29+ betting.matchId,
30+ bettingInfoDto,
31+ bettingResultInfoDto
32+ )
33+ }
34+
35+ return BettingBundleDto (bundleInfo)
36+ }
37+
38+
39+ }
Original file line number Diff line number Diff line change 11package gogo.gogobetting.domain.betting.root.application
22
3- import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleInfoDto
3+ import gogo.gogobetting.domain.betting.root.persistence.Betting
44import gogo.gogobetting.domain.betting.root.persistence.BettingRepository
55import org.springframework.stereotype.Component
66
@@ -9,7 +9,7 @@ class BettingReader(
99 private val bettingRepository : BettingRepository ,
1010) {
1111
12- fun readBundleInfo (matchIds : List <Long >, studentId : Long ): List <BettingBundleInfoDto > =
12+ fun readBundleInfo (matchIds : List <Long >, studentId : Long ): List <Betting > =
1313 bettingRepository.findBettingBundleInfo(matchIds, studentId)
1414
1515}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ class BettingServiceImpl(
1616 private val bettingProcessor : BettingProcessor ,
1717 private val applicationEventPublisher : ApplicationEventPublisher ,
1818 private val bettingReader : BettingReader ,
19+ private val bettingMapper : BettingMapper ,
1920) : BettingService {
2021
2122 @Transactional
@@ -39,8 +40,8 @@ class BettingServiceImpl(
3940
4041 @Transactional(readOnly = true )
4142 override fun bundle (matchIds : List <Long >, studentId : Long ): BettingBundleDto {
42- val bettingBundleInfo = bettingReader.readBundleInfo(matchIds, studentId)
43- return BettingBundleDto (bettingBundleInfo )
43+ val bettings = bettingReader.readBundleInfo(matchIds, studentId)
44+ return bettingMapper.mapBundle(bettings )
4445 }
4546
4647}
Original file line number Diff line number Diff line change 11package gogo.gogobetting.domain.betting.root.persistence
22
3- import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleInfoDto
43import gogo.gogobetting.domain.betting.root.application.dto.MatchOddsDto
54
65interface BettingCustomRepository {
76 fun calcOdds (matchId : Long , winTeamId : Long ): MatchOddsDto
8- fun findBettingBundleInfo (matchIds : List <Long >, studentId : Long ): List <BettingBundleInfoDto >
7+ fun findBettingBundleInfo (matchIds : List <Long >, studentId : Long ): List <Betting >
98}
Original file line number Diff line number Diff line change @@ -44,26 +44,9 @@ class BettingCustomRepositoryImpl(
4444 return MatchOddsDto (odds)
4545 }
4646
47- override fun findBettingBundleInfo (matchIds : List <Long >, studentId : Long ): List <BettingBundleInfoDto > =
47+ override fun findBettingBundleInfo (matchIds : List <Long >, studentId : Long ): List <Betting > =
4848 queryFactory
49- .select(
50- Projections .constructor (
51- BettingBundleInfoDto ::class .java,
52- betting.matchId,
53- Projections .constructor (
54- BettingInfoDto ::class .java,
55- betting.id,
56- betting.point,
57- betting.predictedWinTeamId,
58- ),
59- Projections .constructor (
60- BettingResultInfoDto ::class .java,
61- bettingResult.isPredicted,
62- bettingResult.earnedPoint
63- ).`as `(" result" )
64- )
65- )
66- .from(betting)
49+ .selectFrom(betting)
6750 .leftJoin(bettingResult)
6851 .on(
6952 bettingResult.bettingId.eq(betting.id)
You can’t perform that action at this time.
0 commit comments