✨ Add BetDetail and BetAnswerDetail
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
20ce4c152b
commit
131d7b56be
@ -1,5 +0,0 @@
|
|||||||
package allin.model
|
|
||||||
|
|
||||||
import allin.dto.UserDTO
|
|
||||||
data class BetAction(val id:Int, val coins: Int, val user: String, val bet: Int)
|
|
||||||
data class BetActionCompleted(val id:Int, val coins: Int, val user: UserDTO, val bet: Bet)
|
|
@ -1,11 +0,0 @@
|
|||||||
package allin.routing
|
|
||||||
|
|
||||||
import io.ktor.server.application.*
|
|
||||||
import io.ktor.server.routing.*
|
|
||||||
|
|
||||||
fun Application.BetActionRouter(){
|
|
||||||
routing {
|
|
||||||
route("/BetAction/add"){
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,44 @@
|
|||||||
|
package allin.routing
|
||||||
|
|
||||||
|
import allin.entities.BetsEntity.getBets
|
||||||
|
import allin.entities.ParticipationsEntity.getParticipationEntityFromBetId
|
||||||
|
import allin.entities.ParticipationsEntity.getParticipationEntityFromUserId
|
||||||
|
import allin.ext.hasToken
|
||||||
|
import allin.ext.verifyUserFromToken
|
||||||
|
import allin.model.BetDetail
|
||||||
|
import allin.model.getBetAnswerDetail
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.auth.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
|
fun Application.BetDetailRouter() {
|
||||||
|
routing {
|
||||||
|
authenticate {
|
||||||
|
get("/BetDetail/get/{id}") {
|
||||||
|
hasToken { principal ->
|
||||||
|
verifyUserFromToken(principal) { user, _ ->
|
||||||
|
val id = call.parameters["id"].toString()
|
||||||
|
val participations = getParticipationEntityFromBetId(id)
|
||||||
|
val selectedBet = getBets().find { it.id == id }
|
||||||
|
if (selectedBet != null) {
|
||||||
|
call.respond(
|
||||||
|
HttpStatusCode.Accepted,
|
||||||
|
BetDetail(
|
||||||
|
selectedBet,
|
||||||
|
getBetAnswerDetail(participations),
|
||||||
|
participations.toList(),
|
||||||
|
getParticipationEntityFromUserId(user.username,id).last()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
call.respond(HttpStatusCode.NotFound, "Bet not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue