From ab2c861902fe5da394ba838817ace30854d5d3d4 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Wed, 7 Feb 2024 22:09:51 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20mock=20participation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/allin/data/mock/MockParticipationDataSource.kt | 2 +- Sources/src/main/kotlin/allin/routing/ParticipationRouter.kt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/src/main/kotlin/allin/data/mock/MockParticipationDataSource.kt b/Sources/src/main/kotlin/allin/data/mock/MockParticipationDataSource.kt index 39fc209..c1971d4 100644 --- a/Sources/src/main/kotlin/allin/data/mock/MockParticipationDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/mock/MockParticipationDataSource.kt @@ -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 = diff --git a/Sources/src/main/kotlin/allin/routing/ParticipationRouter.kt b/Sources/src/main/kotlin/allin/routing/ParticipationRouter.kt index 3995a88..7eaeafe 100644 --- a/Sources/src/main/kotlin/allin/routing/ParticipationRouter.kt +++ b/Sources/src/main/kotlin/allin/routing/ParticipationRouter.kt @@ -38,7 +38,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) From 0dd1017e81c133c6307384ef8ad381e4d57974f5 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Wed, 7 Feb 2024 22:17:10 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20toConfirm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/allin/data/mock/MockBetDataSource.kt | 12 +++++++----- .../allin/data/postgres/PostgresBetDataSource.kt | 4 +++- Sources/src/main/kotlin/allin/routing/BetRouter.kt | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt index ca8e046..f7eb3ad 100644 --- a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt @@ -33,11 +33,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 = WAITING) + } else { + bets[idx] = bet.copy(status = CLOSING) + } } } } diff --git a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt index 5bc55f0..fbfba37 100644 --- a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt @@ -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) } } diff --git a/Sources/src/main/kotlin/allin/routing/BetRouter.kt b/Sources/src/main/kotlin/allin/routing/BetRouter.kt index f0b70ed..16d8f01 100644 --- a/Sources/src/main/kotlin/allin/routing/BetRouter.kt +++ b/Sources/src/main/kotlin/allin/routing/BetRouter.kt @@ -92,8 +92,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) From 62aa1bbf9bd205c7dce21a77f577b81bcf1406c8 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Wed, 7 Feb 2024 22:53:44 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20coins=20on=20victory?= =?UTF-8?q?=20(mock)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/allin/data/mock/MockBetDataSource.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt index f7eb3ad..1f64939 100644 --- a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt @@ -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 @@ -62,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)) } } From 30c4cf199f5dfef575ffde3c5848dd3af821a4c5 Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Wed, 7 Feb 2024 23:38:39 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20status=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt | 4 ++-- .../main/kotlin/allin/data/postgres/PostgresBetDataSource.kt | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt index 1f64939..b6339ed 100644 --- a/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/mock/MockBetDataSource.kt @@ -37,9 +37,9 @@ class MockBetDataSource(mockData: MockDataSource.MockData) : BetDataSource { if (bet.status != CANCELLED && bet.status != FINISHED) { if (date >= bet.endRegistration) { if (date >= bet.endBet) { - bets[idx] = bet.copy(status = WAITING) - } else { bets[idx] = bet.copy(status = CLOSING) + } else { + bets[idx] = bet.copy(status = WAITING) } } } diff --git a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt index fbfba37..a16a74c 100644 --- a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt @@ -214,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) } } }