Fixed current bets route 🐛
continuous-integration/drone/push Build is passing Details

pull/7/head
root 1 year ago
parent f80d14bfec
commit 2b3a79bd0f

@ -45,6 +45,25 @@ object BetsEntity : Table<BetEntity>("bet") {
}.toMutableList()
}
fun getBetsNotFinished(): MutableList<Bet> {
val currentTime = ZonedDateTime.now(ZoneId.of("Europe/Paris"))
return database.from(BetsEntity)
.select()
.where { endBet greaterEq currentTime.toInstant() }
.map { row ->
Bet(
row[id].toString(),
row[theme].toString(),
row[sentenceBet].toString(),
row[endRegistration]!!.atZone(ZoneId.of("Europe/Paris")),
row[endBet]!!.atZone(ZoneId.of("Europe/Paris")),
row[isPrivate] ?: false,
getResponse(fromString(row[id].toString())),
row[createdBy].toString()
)
}.toMutableList()
}
fun createBetsTable(){
val request="CREATE TABLE IF not exists bet ( id uuid PRIMARY KEY, theme VARCHAR(255), endregistration timestamp,endbet timestamp,sentencebet varchar(500),isprivate boolean, createdby varchar(250))"
database.Execute(request)

@ -2,7 +2,9 @@ package allin.routing
import allin.entities.BetsEntity.addBetEntity
import allin.entities.BetsEntity.getBets
import allin.entities.BetsEntity.getBetsNotFinished
import allin.entities.ParticipationsEntity.getParticipationEntity
import allin.entities.ParticipationsEntity.getParticipationEntityFromUserId
import allin.ext.hasToken
import allin.ext.verifyUserFromToken
import allin.model.ApiMessage
@ -96,13 +98,15 @@ fun Application.BetRouter() {
authenticate {
get("/bets/current") {
val bets= getBets()
hasToken { principal ->
verifyUserFromToken(principal) { user, _ ->
val bets = getParticipationEntity()
.filter { it.username == user.username }
.mapNotNull { itParticipation -> bets.find { it.id == itParticipation.betId } }
call.respond(HttpStatusCode.OK, bets)
val currentBets = getBetsNotFinished()
.filter { bet ->
val userParticipation = getParticipationEntityFromUserId(user.username, bet.id)
userParticipation.isNotEmpty() || bet.createdBy == user.username
}
call.respond(HttpStatusCode.OK, currentBets)
}
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save