✨ Add Bet and response entity, refactor and modification UserDTO
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
3e59a3224e
commit
a79984e781
@ -1,4 +1,4 @@
|
|||||||
package allin.dto
|
package allin.dto
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@Serializable
|
@Serializable
|
||||||
data class UserDTO(val username: String, val email: String, val nbCoins: Double, var token:String?)
|
data class UserDTO(val id: String, val username: String, val email: String, val nbCoins: Double, var token:String?)
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package allin.entities
|
||||||
|
|
||||||
|
import allin.database
|
||||||
|
import allin.utils.Execute
|
||||||
|
import org.ktorm.dsl.*
|
||||||
|
import org.ktorm.entity.Entity
|
||||||
|
import org.ktorm.schema.Table
|
||||||
|
import org.ktorm.schema.uuid
|
||||||
|
import org.ktorm.schema.varchar
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
|
interface ResponseEntity : Entity<ResponseEntity> {
|
||||||
|
val betId: UUID
|
||||||
|
val response: String
|
||||||
|
}
|
||||||
|
|
||||||
|
object ResponsesEntity : Table<ResponseEntity>("response") {
|
||||||
|
val id = uuid("id").primaryKey()
|
||||||
|
val response = varchar("response").primaryKey()
|
||||||
|
fun createResponseTable(){
|
||||||
|
val request="CREATE TABLE IF NOT EXISTS response (id UUID,response VARCHAR(250),CONSTRAINT pk_response_id PRIMARY KEY (id,response));"
|
||||||
|
database.Execute(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getResponse(idBet: UUID): MutableList<String> {
|
||||||
|
return database.from(ResponsesEntity)
|
||||||
|
.select(response)
|
||||||
|
.where { id eq idBet }
|
||||||
|
.map { it[response].toString() }
|
||||||
|
.toMutableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addResponse(responses : MutableList<String>, idBet : UUID ) {
|
||||||
|
responses.forEach {selected ->
|
||||||
|
database.insert(ResponsesEntity) {
|
||||||
|
set(it.id, idBet)
|
||||||
|
set(it.response,selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue