Skip to content

Commit 62085d1

Browse files
authored
Merge pull request #14 from team-gogo/fix/betting-bundle-query
[betting] 배팅 일괄 조회 repostiroy 수정
2 parents 82de003 + 81b2e26 commit 62085d1

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package 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
44
import gogo.gogobetting.domain.betting.root.persistence.BettingRepository
55
import 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
}

src/main/kotlin/gogo/gogobetting/domain/betting/root/application/BettingServiceImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package gogo.gogobetting.domain.betting.root.persistence
22

3-
import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleInfoDto
43
import gogo.gogobetting.domain.betting.root.application.dto.MatchOddsDto
54

65
interface 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
}

src/main/kotlin/gogo/gogobetting/domain/betting/root/persistence/BettingCustomRepositoryImpl.kt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)