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 { class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource {
private val bets = mockData.bets private val bets = mockData.bets
private val results = mockData.results private val results = mockData.results
private val users = mockData.users
private val participations = mockData.participations private val participations = mockData.participations
private val resultNotifications = mockData.resultNotifications private val resultNotifications = mockData.resultNotifications
@ -33,11 +34,13 @@ class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource {
override fun updateBetStatuses(date: ZonedDateTime) { override fun updateBetStatuses(date: ZonedDateTime) {
bets.forEachIndexed { idx, bet -> bets.forEachIndexed { idx, bet ->
if (bet.status != CANCELLED && bet.status != FINISHED) {
if (date >= bet.endRegistration) { if (date >= bet.endRegistration) {
if (date >= bet.endBet) { if (date >= bet.endBet) {
bets[idx] = bet.copy(status = WAITING)
} else {
bets[idx] = bet.copy(status = CLOSING) 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 } participations.filter { it.betId == betId && it.answer == result }
.forEach { .forEach { participation ->
resultNotifications.add(Pair(betId, it.username)) 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 private val participations = mockData.participations
override fun addParticipation(participation: Participation) { override fun addParticipation(participation: Participation) {
participations += participations participations += participation
} }
override fun getParticipationFromBetId(betid: String): List<Participation> = override fun getParticipationFromBetId(betid: String): List<Participation> =

@ -204,7 +204,9 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
set(BetsEntity.status, BetStatus.WAITING) set(BetsEntity.status, BetStatus.WAITING)
where { where {
(date.toInstant() greaterEq BetsEntity.endRegistration) and (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) set(BetsEntity.status, BetStatus.CLOSING)
where { where {
(date.toInstant() greaterEq BetsEntity.endRegistration) and (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( BetDetail(
it, it,
getBetAnswerDetail(it, participations), getBetAnswerDetail(it, participations),
participations.toList(), participations,
participationDataSource.getParticipationFromUserId(user.username, it.id).lastOrNull() participations.find { it.username == user.username }
) )
} }
call.respond(HttpStatusCode.Accepted, response) call.respond(HttpStatusCode.Accepted, response)

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

Loading…
Cancel
Save