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() }.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(){ 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))" 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) database.Execute(request)

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