Skip to content

Commit 475b88b

Browse files
authored
Merge pull request #149 from team-gogo/feature/stage-wasted-api
[stage] 내가 파산했는지 확인하기 API
2 parents 07ad818 + 67f3f70 commit 475b88b

File tree

12 files changed

+72
-8
lines changed

12 files changed

+72
-8
lines changed

src/main/kotlin/gogo/gogostage/domain/match/root/application/MatchReader.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class MatchReader(
1818

1919
fun readByStageId(stageId: Long): List<Match> = matchRepository.findByStageId(stageId)
2020

21+
fun readNotEndByStageId(stageId: Long): List<Match> = matchRepository.findAllNotEndMatchByStageId(stageId)
22+
2123
fun readMy(matchIds: List<Long>): List<Match> = matchRepository.findMy(matchIds)
2224

2325
fun search(stageId: Long, studentId: Long, y: Int, m: Int, d: Int): List<Match> =

src/main/kotlin/gogo/gogostage/domain/match/root/persistence/MatchRepository.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ interface MatchRepository: JpaRepository<Match, Long>, MatchCustomRepository {
77
@Query("SELECT m FROM Match m WHERE m.id = :matchId AND m.isEnd = false")
88
fun findNotEndMatchById(matchId: Long): Match?
99

10+
@Query("SELECT m FROM Match m WHERE m.game.stage.id = :stageId AND m.isEnd = false")
11+
fun findAllNotEndMatchByStageId(stageId: Long): List<Match>
12+
1013
@Query("SELECT m FROM Match m WHERE m.game.stage.id = :stageId")
1114
fun findByStageId(stageId: Long): List<Match>
1215

src/main/kotlin/gogo/gogostage/domain/stage/root/application/StageProcessor.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import gogo.gogostage.domain.community.root.persistence.CommunityRepository
55
import gogo.gogostage.domain.game.persistence.Game
66
import gogo.gogostage.domain.game.persistence.GameRepository
77
import gogo.gogostage.domain.game.persistence.GameSystem
8+
import gogo.gogostage.domain.match.root.application.MatchReader
89
import gogo.gogostage.domain.match.root.persistence.Match
910
import gogo.gogostage.domain.match.root.persistence.MatchRepository
1011
import gogo.gogostage.domain.stage.maintainer.persistence.StageMaintainer
1112
import gogo.gogostage.domain.stage.maintainer.persistence.StageMaintainerRepository
1213
import gogo.gogostage.domain.stage.minigameinfo.persistence.MiniGameInfo
1314
import gogo.gogostage.domain.stage.minigameinfo.persistence.MiniGameInfoRepository
15+
import gogo.gogostage.domain.stage.participant.root.application.ParticipantReader
1416
import gogo.gogostage.domain.stage.participant.root.persistence.StageParticipant
1517
import gogo.gogostage.domain.stage.participant.root.persistence.StageParticipantRepository
1618
import gogo.gogostage.domain.stage.root.application.dto.CreateFastStageDto
@@ -23,6 +25,7 @@ import gogo.gogostage.domain.stage.rule.persistence.StageRule
2325
import gogo.gogostage.domain.stage.rule.persistence.StageRuleRepository
2426
import gogo.gogostage.domain.team.root.persistence.TeamRepository
2527
import gogo.gogostage.global.error.StageException
28+
import gogo.gogostage.global.internal.betting.api.BettingApi
2629
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
2730
import org.springframework.data.repository.findByIdOrNull
2831
import org.springframework.http.HttpStatus
@@ -39,6 +42,9 @@ class StageProcessor(
3942
private val communityRepository: CommunityRepository,
4043
private val teamRepository: TeamRepository,
4144
private val matchRepository: MatchRepository,
45+
private val participantReader: ParticipantReader,
46+
private val matchReader: MatchReader,
47+
private val bettingApi: BettingApi,
4248
) {
4349

4450
fun saveFast(student: StudentByIdStub, dto: CreateFastStageDto): Stage {
@@ -236,12 +242,19 @@ class StageProcessor(
236242
}
237243
}
238244

239-
private fun factorial(n: Int): Int {
240-
var result = 1
241-
for (i in 2..n) {
242-
result *= i
243-
}
244-
return result
245+
fun isWasted(student: StudentByIdStub, stageId: Long): Boolean {
246+
val stageParticipant = participantReader.read(stageId, student.studentId)
247+
val point = stageParticipant.point
248+
if (point > 0) return false
249+
250+
val totalTempPoint = participantReader.readTempPointNotAppliedList(stageParticipant.id).sumOf { it.tempPoint }
251+
if (totalTempPoint > 0) return false
252+
253+
val matches = matchReader.readNotEndByStageId(stageId)
254+
val totalBettingPoint = bettingApi.totalBettingPoint(matches.map { it.id }, student.studentId).bettingPoint
255+
if (totalBettingPoint > 0) return false
256+
257+
return true
245258
}
246259

247260
}

src/main/kotlin/gogo/gogostage/domain/stage/root/application/StageService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ interface StageService {
1111
fun me(): QueryMyStageDto
1212
fun getPointRank(stageId: Long, page: Int, size: Int): StageParticipantPointRankDto
1313
fun checkMeStageMaintainer(stageId: Long): CheckStageMaintainerDto
14+
fun wasted(stageId: Long): QueryMyWastedDto
1415
}

src/main/kotlin/gogo/gogostage/domain/stage/root/application/StageServiceImpl.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package gogo.gogostage.domain.stage.root.application
22

3+
import gogo.gogostage.domain.match.root.application.MatchReader
34
import gogo.gogostage.domain.stage.maintainer.persistence.StageMaintainerRepository
5+
import gogo.gogostage.domain.stage.participant.root.application.ParticipantReader
46
import gogo.gogostage.domain.stage.root.application.dto.*
57
import gogo.gogostage.domain.stage.root.event.*
68
import gogo.gogostage.domain.stage.root.persistence.StageRepository
79
import gogo.gogostage.global.error.StageException
10+
import gogo.gogostage.global.internal.betting.api.BettingApi
11+
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
812
import gogo.gogostage.global.util.UserContextUtil
913
import org.springframework.context.ApplicationEventPublisher
1014
import org.springframework.http.HttpStatus
@@ -21,7 +25,10 @@ class StageServiceImpl(
2125
private val applicationEventPublisher: ApplicationEventPublisher,
2226
private val stageRepository: StageRepository,
2327
private val stageReader: StageReader,
24-
private val stageMaintainerRepository: StageMaintainerRepository
28+
private val stageMaintainerRepository: StageMaintainerRepository,
29+
private val matchReader: MatchReader,
30+
private val bettingApi: BettingApi,
31+
private val participantReader: ParticipantReader
2532
) : StageService {
2633

2734
@Transactional
@@ -113,4 +120,12 @@ class StageServiceImpl(
113120
return stageMapper.mapCheckMaintainerDto(isMaintainer)
114121
}
115122

123+
@Transactional(readOnly = true)
124+
override fun wasted(stageId: Long): QueryMyWastedDto {
125+
val student = userUtil.getCurrentStudent()
126+
stageValidator.validStage(student, stageId)
127+
val isWasted = stageProcessor.isWasted(student, stageId)
128+
return QueryMyWastedDto(isWasted)
129+
}
130+
116131
}

src/main/kotlin/gogo/gogostage/domain/stage/root/application/dto/StageDto.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,8 @@ data class PointRankDto(
191191

192192
data class CheckStageMaintainerDto(
193193
val isMaintainer: Boolean
194-
)
194+
)
195+
196+
data class QueryMyWastedDto(
197+
val isWasted: Boolean
198+
)

src/main/kotlin/gogo/gogostage/domain/stage/root/presentation/StageController.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ class StageController(
7777
return ResponseEntity.ok(response)
7878
}
7979

80+
@GetMapping("/wasted/me/{stage_id}")
81+
fun wasted(
82+
@PathVariable("stage_id") stageId: Long,
83+
): ResponseEntity<QueryMyWastedDto> {
84+
val response = stageService.wasted(stageId)
85+
return ResponseEntity.ok(response)
86+
}
87+
8088
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SecurityConfig(
7474
httpRequests.requestMatchers(HttpMethod.GET, "/stage/point/me/{stage_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
7575
httpRequests.requestMatchers(HttpMethod.GET, "/stage/rule/{stage_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
7676
httpRequests.requestMatchers(HttpMethod.GET, "/stage/game/format/{game_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
77+
httpRequests.requestMatchers(HttpMethod.GET, "/stage/wasted/me/{stage_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)
7778

7879
// match
7980
httpRequests.requestMatchers(HttpMethod.GET, "/stage/match/search/{stage_id}").hasAnyRole(Authority.USER.name, Authority.STAFF.name)

src/main/kotlin/gogo/gogostage/global/feign/client/BettingClient.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gogo.gogostage.global.feign.client
22

33
import gogo.gogostage.global.internal.betting.stub.BettingBundleDto
4+
import gogo.gogostage.global.internal.betting.stub.TotalBettingPointDto
45
import org.springframework.cloud.openfeign.FeignClient
56
import org.springframework.web.bind.annotation.GetMapping
67
import org.springframework.web.bind.annotation.RequestParam
@@ -12,4 +13,10 @@ interface BettingClient {
1213
@RequestParam("matchIds") matchIds: List<Long>,
1314
@RequestParam("studentId") studentId: Long
1415
): BettingBundleDto
16+
17+
@GetMapping("/betting/point")
18+
fun totalBettingPoint(
19+
@RequestParam("matchIds") matchIds: List<Long>,
20+
@RequestParam("studentId") studentId: Long
21+
): TotalBettingPointDto
1522
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package gogo.gogostage.global.internal.betting.api
22

33
import gogo.gogostage.global.internal.betting.stub.BettingBundleDto
4+
import gogo.gogostage.global.internal.betting.stub.TotalBettingPointDto
45

56
interface BettingApi {
67
fun bundle(matchIds: List<Long>, studentId: Long): BettingBundleDto
8+
fun totalBettingPoint(matchIds: List<Long>, studentId: Long): TotalBettingPointDto
79
}

0 commit comments

Comments
 (0)