Merge remote-tracking branch 'origin/master'
continuous-integration/drone/push Build is passing Details

pull/12/head
Lucas EVARD 1 year ago
commit 5847fbe32d

@ -8,6 +8,7 @@ import java.time.ZonedDateTime
class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource {
private val bets = mockData.bets
private val results = mockData.results
private val users = mockData.users
private val participations = mockData.participations
private val resultNotifications = mockData.resultNotifications
@ -33,11 +34,13 @@ class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource {
override fun updateBetStatuses(date: ZonedDateTime) {
bets.forEachIndexed { idx, bet ->
if (date >= bet.endRegistration) {
if (date >= bet.endBet) {
bets[idx] = bet.copy(status = WAITING)
} else {
bets[idx] = bet.copy(status = CLOSING)
if (bet.status != CANCELLED && bet.status != FINISHED) {
if (date >= bet.endRegistration) {
if (date >= bet.endBet) {
bets[idx] = bet.copy(status = CLOSING)
} else {
bets[idx] = bet.copy(status = WAITING)
}
}
}
}
@ -60,8 +63,13 @@ class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource {
}
participations.filter { it.betId == betId && it.answer == result }
.forEach {
resultNotifications.add(Pair(betId, it.username))
.forEach { participation ->
users.replaceAll {
if (it.username == participation.username) {
it.copy(nbCoins = it.nbCoins + participation.stake)
} else it
}
resultNotifications.add(Pair(betId, participation.username))
}
}

@ -7,7 +7,7 @@ class MockParticipationDataSource(mockData: MockDataSource.MockData) : Participa
private val participations = mockData.participations
override fun addParticipation(participation: Participation) {
participations += participations
participations += participation
}
override fun getParticipationFromBetId(betid: String): List<Participation> =

@ -204,7 +204,9 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
set(BetsEntity.status, BetStatus.WAITING)
where {
(date.toInstant() greaterEq BetsEntity.endRegistration) and
(date.toInstant() less BetsEntity.endBet)
(date.toInstant() less BetsEntity.endBet) and
(BetsEntity.status notEq BetStatus.FINISHED) and
(BetsEntity.status notEq BetStatus.CANCELLED)
}
}
@ -212,7 +214,9 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
set(BetsEntity.status, BetStatus.CLOSING)
where {
(date.toInstant() greaterEq BetsEntity.endRegistration) and
(date.toInstant() greaterEq BetsEntity.endBet)
(date.toInstant() greaterEq BetsEntity.endBet) and
(BetsEntity.status notEq BetStatus.FINISHED) and
(BetsEntity.status notEq BetStatus.CANCELLED)
}
}
}

@ -182,8 +182,8 @@ fun Application.BetRouter() {
BetDetail(
it,
getBetAnswerDetail(it, participations),
participations.toList(),
participationDataSource.getParticipationFromUserId(user.username, it.id).lastOrNull()
participations,
participations.find { it.username == user.username }
)
}
call.respond(HttpStatusCode.Accepted, response)

@ -59,7 +59,6 @@ fun Application.ParticipationRouter() {
)
userDataSource.removeCoins(username = user.username, amount = participation.stake)
call.respond(HttpStatusCode.Created)
} else {
call.respond(HttpStatusCode.Forbidden, ApiMessage.NOT_ENOUGH_COINS)

Loading…
Cancel
Save