|
|
@ -55,8 +55,8 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
override fun getBetById(id: String): Bet? =
|
|
|
|
override fun getBetById(id: String): Bet? =
|
|
|
|
database.bets.find { it.id eq id }?.toBet(database)
|
|
|
|
database.bets.find { it.id eq id }?.toBet(database)
|
|
|
|
|
|
|
|
|
|
|
|
override fun getBetDetailById(id: String, username: String): BetDetail? =
|
|
|
|
override fun getBetDetailById(id: String, userid: String): BetDetail? =
|
|
|
|
database.bets.find { it.id eq id }?.toBetDetail(database, username)
|
|
|
|
database.bets.find { it.id eq id }?.toBetDetail(database, userid)
|
|
|
|
|
|
|
|
|
|
|
|
override fun getBetsNotFinished(): List<Bet> {
|
|
|
|
override fun getBetsNotFinished(): List<Bet> {
|
|
|
|
val currentTime = ZonedDateTime.now(ZoneId.of("+02:00"))
|
|
|
|
val currentTime = ZonedDateTime.now(ZoneId.of("+02:00"))
|
|
|
@ -70,7 +70,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
.filter {
|
|
|
|
.filter {
|
|
|
|
(it.createdBy eq user.id) and (BetsEntity.status eq BetStatus.CLOSING)
|
|
|
|
(it.createdBy eq user.id) and (BetsEntity.status eq BetStatus.CLOSING)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map { it.toBetDetail(database, user.username) }
|
|
|
|
.map { it.toBetDetail(database, user.id) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun confirmBet(betId: String, result: String) {
|
|
|
|
override fun confirmBet(betId: String, result: String) {
|
|
|
@ -97,27 +97,27 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
database.betResultNotifications.add(
|
|
|
|
database.betResultNotifications.add(
|
|
|
|
BetResultNotificationEntity {
|
|
|
|
BetResultNotificationEntity {
|
|
|
|
this.betId = betId
|
|
|
|
this.betId = betId
|
|
|
|
this.username = participation.username
|
|
|
|
this.userid = participation.userid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
val amount = (participation.stake * (resultAnswerInfo?.odds ?: 1f)).roundToInt()
|
|
|
|
val amount = (participation.stake * (resultAnswerInfo?.odds ?: 1f)).roundToInt()
|
|
|
|
database.update(UsersEntity) { usr ->
|
|
|
|
database.update(UsersEntity) { usr ->
|
|
|
|
set(usr.nbCoins, usr.nbCoins + amount)
|
|
|
|
set(usr.nbCoins, usr.nbCoins + amount)
|
|
|
|
where { usr.username eq participation.username }
|
|
|
|
where { usr.id eq participation.userid }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getWonNotifications(username: String): List<BetResultDetail> {
|
|
|
|
override fun getWonNotifications(userid: String): List<BetResultDetail> {
|
|
|
|
return database.betResultNotifications
|
|
|
|
return database.betResultNotifications
|
|
|
|
.filter { it.username eq username }
|
|
|
|
.filter { it.userid eq userid }
|
|
|
|
.flatMap { notif ->
|
|
|
|
.flatMap { notif ->
|
|
|
|
notif.delete()
|
|
|
|
notif.delete()
|
|
|
|
|
|
|
|
|
|
|
|
database.participations
|
|
|
|
database.participations
|
|
|
|
.filter {
|
|
|
|
.filter {
|
|
|
|
(it.username eq username) and
|
|
|
|
(it.id eq userid) and
|
|
|
|
(it.betId eq notif.betId)
|
|
|
|
(it.betId eq notif.betId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.mapNotNull { participation ->
|
|
|
|
.mapNotNull { participation ->
|
|
|
@ -132,9 +132,9 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getHistory(username: String): List<BetResultDetail> {
|
|
|
|
override fun getHistory(userid: String): List<BetResultDetail> {
|
|
|
|
return database.participations
|
|
|
|
return database.participations
|
|
|
|
.filter { it.username eq username }
|
|
|
|
.filter { it.userid eq userid }
|
|
|
|
.mapNotNull { participation ->
|
|
|
|
.mapNotNull { participation ->
|
|
|
|
database.betResults
|
|
|
|
database.betResults
|
|
|
|
.find { it.betId eq participation.bet.id }
|
|
|
|
.find { it.betId eq participation.bet.id }
|
|
|
@ -145,14 +145,14 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getCurrent(username: String): List<BetDetail> {
|
|
|
|
override fun getCurrent(userid: String): List<BetDetail> {
|
|
|
|
return database.participations
|
|
|
|
return database.participations
|
|
|
|
.filter { it.username eq username }
|
|
|
|
.filter { it.userid eq userid }
|
|
|
|
.mapNotNull {
|
|
|
|
.mapNotNull {
|
|
|
|
if (it.bet.status !in listOf(BetStatus.FINISHED, BetStatus.CANCELLED)) {
|
|
|
|
if (it.bet.status !in listOf(BetStatus.FINISHED, BetStatus.CANCELLED)) {
|
|
|
|
it.bet.toBetDetail(
|
|
|
|
it.bet.toBetDetail(
|
|
|
|
database = database,
|
|
|
|
database = database,
|
|
|
|
username = username
|
|
|
|
userid = userid
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else null
|
|
|
|
} else null
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -257,7 +257,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
|
|
|
|
database.participations
|
|
|
|
database.participations
|
|
|
|
.filter { it.betId eq bet.id }
|
|
|
|
.filter { it.betId eq bet.id }
|
|
|
|
.forEach { participation ->
|
|
|
|
.forEach { participation ->
|
|
|
|
database.users.find { it.username eq participation.username }?.let { user ->
|
|
|
|
database.users.find { it.id eq participation.userid }?.let { user ->
|
|
|
|
user.nbCoins += participation.stake
|
|
|
|
user.nbCoins += participation.stake
|
|
|
|
user.flushChanges()
|
|
|
|
user.flushChanges()
|
|
|
|
}
|
|
|
|
}
|
|
|
|