Skip to content

Commit 855dbb0

Browse files
authored
Merge pull request #24 from team-gogo/feature/total-betting-point-api
[betting] 학생 ID, 매치ID들로 총 배팅 포인트 확인하기 Internal API
2 parents b4e399f + 8629d3d commit 855dbb0

File tree

9 files changed

+47
-4
lines changed

9 files changed

+47
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package gogo.gogobetting.domain.betting.root.application
22

33
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
4+
import gogo.gogobetting.domain.betting.root.application.dto.*
85
import gogo.gogobetting.domain.betting.root.persistence.Betting
96
import org.springframework.stereotype.Component
107

@@ -35,5 +32,9 @@ class BettingMapper(
3532
return BettingBundleDto(bundleInfo)
3633
}
3734

35+
fun mapBettingPoint(bettingList: List<Betting>): TotalBettingPointDto =
36+
TotalBettingPointDto(
37+
bettingPoint = bettingList.sumOf { it.point }
38+
)
3839

3940
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ class BettingReader(
1212
fun readBundleInfo(matchIds: List<Long>, studentId: Long): List<Betting> =
1313
bettingRepository.findBettingBundleInfo(matchIds, studentId)
1414

15+
fun readBundleActiveInfo(matchIds: List<Long>, studentId: Long): List<Betting> =
16+
bettingRepository.findBettingActiveBundleInfo(matchIds, studentId)
17+
1518
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package gogo.gogobetting.domain.betting.root.application
22

33
import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleDto
44
import gogo.gogobetting.domain.betting.root.application.dto.BettingDto
5+
import gogo.gogobetting.domain.betting.root.application.dto.TotalBettingPointDto
56

67
interface BettingService {
78
fun bet(matchId: Long, dto: BettingDto)
89
fun bundle(matchIds: List<Long>, studentId: Long): BettingBundleDto
10+
fun totalBettingPoint(matchIds: List<Long>, studentId: Long): TotalBettingPointDto
911
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gogo.gogobetting.domain.betting.root.application
22

33
import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleDto
44
import gogo.gogobetting.domain.betting.root.application.dto.BettingDto
5+
import gogo.gogobetting.domain.betting.root.application.dto.TotalBettingPointDto
56
import gogo.gogobetting.domain.betting.root.event.MatchBettingEvent
67
import gogo.gogobetting.global.util.UserContextUtil
78
import org.springframework.context.ApplicationEventPublisher
@@ -43,4 +44,10 @@ class BettingServiceImpl(
4344
return bettingMapper.mapBundle(bettings)
4445
}
4546

47+
@Transactional(readOnly = true)
48+
override fun totalBettingPoint(matchIds: List<Long>, studentId: Long): TotalBettingPointDto {
49+
val bettings = bettingReader.readBundleActiveInfo(matchIds, studentId)
50+
return bettingMapper.mapBettingPoint(bettings)
51+
}
52+
4653
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ data class BettingResultInfoDto(
3434
val earnedPoint: Long,
3535
)
3636

37+
data class TotalBettingPointDto(
38+
val bettingPoint: Long,
39+
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import gogo.gogobetting.domain.betting.root.application.dto.MatchOddsDto
55
interface BettingCustomRepository {
66
fun calcOdds(matchId: Long, winTeamId: Long): MatchOddsDto
77
fun findBettingBundleInfo(matchIds: List<Long>, studentId: Long): List<Betting>
8+
fun findBettingActiveBundleInfo(matchIds: List<Long>, studentId: Long): List<Betting>
89
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ class BettingCustomRepositoryImpl(
5959
)
6060
.fetch()
6161

62+
override fun findBettingActiveBundleInfo(matchIds: List<Long>, studentId: Long): List<Betting> =
63+
queryFactory
64+
.selectFrom(betting)
65+
.leftJoin(bettingResult)
66+
.on(
67+
bettingResult.bettingId.eq(betting.id)
68+
)
69+
.where(
70+
betting.matchId.`in`(matchIds)
71+
.and(betting.studentId.eq(studentId))
72+
.and(betting.status.eq(CONFIRMED))
73+
.and(bettingResult.isNull)
74+
)
75+
.fetch()
76+
6277
}

src/main/kotlin/gogo/gogobetting/domain/betting/root/presentation/BettingController.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gogo.gogobetting.domain.betting.root.presentation
33
import gogo.gogobetting.domain.betting.root.application.BettingService
44
import gogo.gogobetting.domain.betting.root.application.dto.BettingBundleDto
55
import gogo.gogobetting.domain.betting.root.application.dto.BettingDto
6+
import gogo.gogobetting.domain.betting.root.application.dto.TotalBettingPointDto
67
import jakarta.validation.Valid
78
import jakarta.validation.constraints.NotNull
89
import org.springframework.http.HttpStatus
@@ -33,4 +34,13 @@ class BettingController(
3334
return ResponseEntity.ok(response)
3435
}
3536

37+
@GetMapping("/point")
38+
fun totalBettingPoint(
39+
@RequestParam @Valid @NotNull matchIds: List<Long>,
40+
@RequestParam @Valid @NotNull studentId: Long
41+
): ResponseEntity<TotalBettingPointDto> {
42+
val response = bettingService.totalBettingPoint(matchIds, studentId)
43+
return ResponseEntity.ok(response)
44+
}
45+
3646
}

src/main/kotlin/gogo/gogobetting/global/config/SecurityConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SecurityConfig(
6363

6464
// server to server
6565
httpRequests.requestMatchers(HttpMethod.GET, "/betting/bundle").access { _, context -> hasIpAddress(context) }
66+
httpRequests.requestMatchers(HttpMethod.GET, "/betting/point").access { _, context -> hasIpAddress(context) }
6667

6768
httpRequests.anyRequest().denyAll()
6869
}

0 commit comments

Comments
 (0)