Saving UUID of the user who created a bet
continuous-integration/drone/push Build is passing Details

pull/12/head
luevard 11 months ago
parent dc929370d1
commit 8f75e78f3c

@ -10,7 +10,6 @@ import allin.utils.kronJob
import com.typesafe.config.ConfigFactory
import io.github.smiley4.ktorswaggerui.SwaggerUI
import io.github.smiley4.ktorswaggerui.data.SwaggerUiSort
import io.github.smiley4.ktorswaggerui.data.SwaggerUiSyntaxHighlight
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
@ -22,7 +21,6 @@ import io.ktor.server.plugins.contentnegotiation.*
import java.time.ZonedDateTime
import kotlin.time.Duration.Companion.minutes
import kotlin.time.ExperimentalTime
import kotlin.time.minutes
@ExperimentalTime
val BET_VERIFY_DELAY = 1.minutes
@ -60,11 +58,11 @@ private fun Application.extracted() {
}
}
install(ContentNegotiation) { json() }
install(SwaggerUI){
install(SwaggerUI) {
swagger {
swaggerUrl = "swagger"
rootHostPath= isCodeFirstContainer
swaggerUrl= "$isCodeFirstContainer/swagger"
rootHostPath = isCodeFirstContainer
swaggerUrl = "$isCodeFirstContainer/swagger"
onlineSpecValidator()
displayOperationId = true
showTagFilterInput = true

@ -1,12 +1,18 @@
package allin.dto
import io.github.smiley4.ktorswaggerui.dsl.Example
import kotlinx.serialization.Serializable
@Serializable
data class UserDTO(
@Example("cabb366c-5a47-4b0f-81e1-25a08fe2c2fe")
val id: String,
@Example("Steve")
val username: String,
@Example("stevemaroco@gmail.com")
val email: String,
@Example("16027")
val nbCoins: Int,
@Example("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwOi8vMC4wLjAuMDo4MDgwLyIsImlzcyI6Imh0dHA6Ly8wLjAuMC4wOjgwODAvIiwidXNlcm5hbWUiOiJ0ZXN0IiwiZXhwIjoxNzA3OTIyNjY1fQ.TwaT9Rd4Xkhg3l4fHiba0IEqnM7xUGJVFRrr5oaWOwQ")
var token: String?
)

@ -1,31 +1,43 @@
package allin.model
import io.github.smiley4.ktorswaggerui.dsl.Example
import kotlinx.serialization.Serializable
import kotlin.random.Random
@Serializable
@Serializable
data class User(
@Example("cabb366c-5a47-4b0f-81e1-25a08fe2c2fe")
val id: String,
@Example("Steve")
val username: String,
@Example("stevemaroco@gmail.com")
val email: String,
@Example("MarocoSteveHDOIU978*")
var password: String,
@Example("16027")
var nbCoins: Int = 500,
@Example("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwOi8vMC4wLjAuMDo4MDgwLyIsImlzcyI6Imh0dHA6Ly8wLjAuMC4wOjgwODAvIiwidXNlcm5hbWUiOiJ0ZXN0IiwiZXhwIjoxNzA3OTIyNjY1fQ.TwaT9Rd4Xkhg3l4fHiba0IEqnM7xUGJVFRrr5oaWOwQ")
var token: String? = null
)
@Serializable
data class UserRequest(
@Example("Steve")
val username: String,
@Example("stevemaroco@gmail.com")
val email: String,
@Example("MarocoSteveHDOIU978*")
var password: String
)
@Serializable
data class CheckUser(
@Example("stevemaroco@gmail.com")
val login: String,
@Example("MarocoSteveHDOIU978*")
val password: String
)
fun getDailyGift() : Int{
fun getDailyGift() : Int{
return Random.nextInt(10,150)
}
}

@ -53,10 +53,11 @@ fun Application.BetRouter() {
val bet = call.receive<Bet>()
val id = UUID.randomUUID().toString()
val username = tokenManagerBet.getUsernameFromToken(principal)
val user = userDataSource.getUserByUsername(username)
betDataSource.getBetById(id)?.let {
call.respond(HttpStatusCode.Conflict, ApiMessage.BET_ALREADY_EXIST)
} ?: run {
val betWithId = bet.copy(id = id, createdBy = username)
val betWithId = bet.copy(id = id, createdBy = user.first?.id.toString())
betDataSource.addBet(betWithId)
call.respond(HttpStatusCode.Created, betWithId)
}

@ -39,7 +39,9 @@ fun Application.UserRouter() {
response {
HttpStatusCode.Created to {
description = "User created"
body<User>()
body<User>{
description="The new user"
}
}
HttpStatusCode.Conflict to {
description = "Email or username already taken"
@ -76,7 +78,7 @@ fun Application.UserRouter() {
post("/users/login", {
description = "Allows a user to login"
request {
body<UserRequest> {
body<CheckUser> {
description = "User information"
}
}
@ -173,7 +175,7 @@ fun Application.UserRouter() {
response {
HttpStatusCode.OK to {
description = "Daily gift allowed !"
body<Int>() {
body<Int> {
description = "Number of coins offered"
}
}

Loading…
Cancel
Save