parent
d7e26c8932
commit
980688bf2a
@ -0,0 +1,8 @@
|
|||||||
|
package allin.model
|
||||||
|
|
||||||
|
import allin.serializer.DateSerializer
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Bet(val id: Int, val theme: String, val sentenceBet: String, @Serializable(DateSerializer::class) val endRegistration: Date, @Serializable(DateSerializer::class) val endBet : Date, val isPrivate : Boolean, val response : MutableList<String>)
|
@ -0,0 +1,29 @@
|
|||||||
|
package allin.routing
|
||||||
|
import io.ktor.server.application.*
|
||||||
|
import io.ktor.server.request.*
|
||||||
|
import io.ktor.server.routing.*
|
||||||
|
import allin.model.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.response.*
|
||||||
|
|
||||||
|
val bets = mutableListOf<Bet>()
|
||||||
|
fun Application.BetRouter(){
|
||||||
|
routing{
|
||||||
|
route("/bets/add"){
|
||||||
|
post{
|
||||||
|
val bet = call.receive<Bet>()
|
||||||
|
val findbet = bets.find { it.id == bet.id }
|
||||||
|
if(findbet==null){
|
||||||
|
bets.add(bet)
|
||||||
|
call.respond(HttpStatusCode.Created, bet)
|
||||||
|
}
|
||||||
|
call.respond(HttpStatusCode.Conflict,"Bet already exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
route("/bets/delete"){
|
||||||
|
post{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package allin.serializer
|
||||||
|
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Serializer(Date::class)
|
||||||
|
class DateSerializer : KSerializer<Date> {
|
||||||
|
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.STRING)
|
||||||
|
|
||||||
|
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.FRANCE)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): Date {
|
||||||
|
val dateString = decoder.decodeString()
|
||||||
|
return formatter.parse(dateString)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: Date) {
|
||||||
|
val dateString = formatter.format(value)
|
||||||
|
encoder.encodeString(dateString)
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
|||||||
|
secret="secret"
|
||||||
|
issuer="http://0.0.0.0:8080/"
|
||||||
|
audience="http://0.0.0.0:8080/"
|
||||||
|
realm="Access to main page"
|
Loading…
Reference in new issue