Remove cast UUID to String
continuous-integration/drone/push Build is passing Details

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

@ -37,7 +37,7 @@ val Application.dataSource: AllInDataSource
get() = allInDataSource
fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
embeddedServer(Netty, port = 10001, host = "0.0.0.0") {
extracted()
}.start(wait = true)
}

@ -8,7 +8,6 @@ import org.ktorm.database.Database
import org.ktorm.dsl.*
import java.time.ZoneId
import java.time.ZonedDateTime
import java.util.*
class PostgresBetDataSource(private val database: Database) : BetDataSource {
@ -29,7 +28,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
if (type == BetType.CUSTOM) {
database.from(ResponsesEntity)
.select(response)
.where { ResponsesEntity.id eq UUID.fromString(idBet) }
.where { ResponsesEntity.id eq idBet }
.map { it[response].toString() }
} else {
listOf(YES_VALUE, NO_VALUE)
@ -66,7 +65,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
override fun getBetById(id: String): Bet? =
database.from(BetsEntity).select().where {
BetsEntity.id eq UUID.fromString(id)
BetsEntity.id eq id
}.mapToBet().firstOrNull()
override fun getBetsNotFinished(): List<Bet> {
@ -93,14 +92,14 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
}
database.update(BetsEntity) {
where { BetsEntity.id eq UUID.fromString(betId) }
where { BetsEntity.id eq betId }
set(BetsEntity.status, BetStatus.FINISHED)
}
database.from(ParticipationsEntity)
.select()
.where {
(ParticipationsEntity.betId eq UUID.fromString(betId)) and
(ParticipationsEntity.betId eq betId) and
(ParticipationsEntity.answer eq result)
}
.forEach { participation ->
@ -167,7 +166,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
override fun addBet(bet: Bet) {
database.insert(BetsEntity) {
set(it.id, UUID.fromString(bet.id))
set(it.id, bet.id)
set(it.endBet, bet.endBet.toInstant())
set(it.endRegistration, bet.endRegistration.toInstant())
set(it.sentenceBet, bet.sentenceBet)
@ -181,7 +180,7 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
if (bet.type == BetType.CUSTOM) {
bet.response.forEach { selected ->
database.insert(ResponsesEntity) {
set(it.id, UUID.fromString(bet.id))
set(it.id, bet.id)
set(it.response, selected)
}
}
@ -189,13 +188,13 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
}
override fun removeBet(id: String): Boolean {
return database.delete(BetsEntity) { it.id eq UUID.fromString(id) } > 0
return database.delete(BetsEntity) { it.id eq id } > 0
}
override fun updateBet(data: UpdatedBetData): Boolean {
return database.update(BetsEntity) {
set(BetsEntity.isPrivate, data.isPrivate)
where { BetsEntity.id eq UUID.fromString(data.id) }
where { BetsEntity.id eq data.id }
} > 0
}

@ -26,10 +26,10 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF not exists utilisateur (
id uuid PRIMARY KEY,
id VARCHAR(255) PRIMARY KEY,
username VARCHAR(255),
password VARCHAR(255),
coins double precision,
coins int,
email VARCHAR(255),
lastgift timestamp
)
@ -39,7 +39,7 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF not exists bet (
id uuid PRIMARY KEY,
id VARCHAR(255) PRIMARY KEY,
theme VARCHAR(255),
endregistration timestamp,
endbet timestamp,
@ -55,7 +55,7 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF NOT EXISTS betresult (
betid uuid PRIMARY KEY REFERENCES bet,
betid VARCHAR(255) PRIMARY KEY REFERENCES bet,
result varchar(250)
)
""".trimIndent()
@ -64,7 +64,7 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF NOT EXISTS betresultnotification (
betid uuid,
betid VARCHAR(255),
username varchar(250),
CONSTRAINT pk_id_username PRIMARY KEY (betid, username)
)
@ -74,8 +74,8 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF NOT EXISTS participation (
id uuid PRIMARY KEY,
bet uuid,
id VARCHAR(255) PRIMARY KEY,
bet VARCHAR(255),
username varchar(250),
answer varchar(250),
stake int
@ -86,7 +86,7 @@ class PostgresDataSource : AllInDataSource() {
database.Execute(
"""
CREATE TABLE IF NOT EXISTS response (
id UUID,
id VARCHAR(255),
response VARCHAR(250),
CONSTRAINT pk_response_id PRIMARY KEY (id, response)
)

@ -5,7 +5,6 @@ import allin.data.postgres.entities.ParticipationsEntity
import allin.model.Participation
import org.ktorm.database.Database
import org.ktorm.dsl.*
import java.util.*
class PostgresParticipationDataSource(private val database: Database) : ParticipationDataSource {
@ -22,8 +21,8 @@ class PostgresParticipationDataSource(private val database: Database) : Particip
override fun addParticipation(participation: Participation) {
database.insert(ParticipationsEntity) {
set(it.id, UUID.fromString(participation.id))
set(it.betId, UUID.fromString(participation.betId))
set(it.id, participation.id)
set(it.betId, participation.betId)
set(it.username, participation.username)
set(it.answer, participation.answer)
set(it.stake, participation.stake)
@ -33,13 +32,13 @@ class PostgresParticipationDataSource(private val database: Database) : Particip
override fun getParticipationFromBetId(betid: String): List<Participation> =
database.from(ParticipationsEntity)
.select()
.where { ParticipationsEntity.betId eq UUID.fromString(betid) }
.where { ParticipationsEntity.betId eq betid }
.mapToParticipation()
override fun getParticipationFromUserId(username: String, betid: String): List<Participation> =
database.from(ParticipationsEntity)
.select()
.where { (ParticipationsEntity.betId eq UUID.fromString(betid)) and (ParticipationsEntity.username eq username) }
.where { (ParticipationsEntity.betId eq betid) and (ParticipationsEntity.username eq username) }
.mapToParticipation()
fun getParticipationEntity(): List<Participation> =
@ -47,6 +46,6 @@ class PostgresParticipationDataSource(private val database: Database) : Particip
override fun deleteParticipation(id: String): Boolean =
database.delete(ParticipationsEntity) {
it.id eq UUID.fromString(id)
it.id eq id
} > 0
}

@ -9,7 +9,6 @@ import org.ktorm.database.Database
import org.ktorm.database.use
import org.ktorm.dsl.*
import java.time.Instant.now
import java.util.*
class PostgresUserDataSource(private val database: Database) : UserDataSource {
override fun getUserByUsername(username: String): Pair<UserDTO?, String?> =
@ -32,7 +31,7 @@ class PostgresUserDataSource(private val database: Database) : UserDataSource {
override fun addUser(user: User) {
database.insert(UsersEntity) {
set(it.id, UUID.fromString(user.id))
set(it.id, user.id)
set(it.nbCoins, user.nbCoins)
set(it.username, user.username)
set(it.password, user.password)

@ -19,7 +19,7 @@ interface BetEntity : Entity<BetEntity> {
}
object BetsEntity : Table<BetEntity>("bet") {
val id = uuid("id").primaryKey()
val id = varchar("id").primaryKey()
val theme = varchar("theme").bindTo { it.theme }
val sentenceBet = varchar("sentencebet").bindTo { it.sentenceBet }
val endRegistration = timestamp("endregistration")

@ -2,9 +2,7 @@ package allin.data.postgres.entities
import org.ktorm.entity.Entity
import org.ktorm.schema.Table
import org.ktorm.schema.uuid
import org.ktorm.schema.varchar
import java.util.*
interface BetResultEntity : Entity<BetResultEntity> {
@ -13,16 +11,16 @@ interface BetResultEntity : Entity<BetResultEntity> {
}
object BetResultsEntity : Table<BetResultEntity>("betresult") {
val betId = uuid("betid").primaryKey().references(BetsEntity) { it.bet }
val betId = varchar("betid").primaryKey().references(BetsEntity) { it.bet }
val result = varchar("result").bindTo { it.result }
}
interface BetResultNotificationEntity : Entity<BetResultNotificationEntity> {
val betId: UUID
val betId: String
val username: String
}
object BetResultNotificationsEntity : Table<BetResultNotificationEntity>("betresult") {
val betId = uuid("betid").primaryKey()
val betId = varchar("betid").primaryKey()
val username = varchar("username").primaryKey()
}

@ -3,7 +3,6 @@ package allin.data.postgres.entities
import org.ktorm.entity.Entity
import org.ktorm.schema.Table
import org.ktorm.schema.int
import org.ktorm.schema.uuid
import org.ktorm.schema.varchar
interface ParticipationEntity : Entity<ParticipationEntity> {
@ -16,8 +15,8 @@ interface ParticipationEntity : Entity<ParticipationEntity> {
object ParticipationsEntity : Table<ParticipationEntity>("participation") {
val id = uuid("id").primaryKey()
val betId = uuid("bet").references(BetsEntity) { it.bet }
val id = varchar("id").primaryKey()
val betId = varchar("bet").references(BetsEntity) { it.bet }
val username = varchar("username")
val answer = varchar("answer")
val stake = int("stake")

@ -2,20 +2,18 @@ package allin.data.postgres.entities
import org.ktorm.entity.Entity
import org.ktorm.schema.Table
import org.ktorm.schema.uuid
import org.ktorm.schema.varchar
import java.util.*
const val YES_VALUE = "Yes"
const val NO_VALUE = "No"
interface ResponseEntity : Entity<ResponseEntity> {
val betId: UUID
val betId: String
val response: String
}
object ResponsesEntity : Table<ResponseEntity>("response") {
val id = uuid("id").primaryKey()
val id = varchar("id").primaryKey()
val response = varchar("response").primaryKey()
}

@ -1,7 +1,10 @@
package allin.data.postgres.entities
import org.ktorm.entity.Entity
import org.ktorm.schema.*
import org.ktorm.schema.Table
import org.ktorm.schema.int
import org.ktorm.schema.timestamp
import org.ktorm.schema.varchar
interface UserEntity : Entity<UserEntity> {
val username: String
@ -11,7 +14,7 @@ interface UserEntity : Entity<UserEntity> {
}
object UsersEntity : Table<UserEntity>("utilisateur") {
val id = uuid("id").primaryKey()
val id = varchar("id").primaryKey()
val username = varchar("username").bindTo { it.username }
val password = varchar("password").bindTo { it.password }
val nbCoins = int("coins").bindTo { it.nbCoins }

@ -52,7 +52,7 @@ fun Application.ParticipationRouter() {
Participation(
id = UUID.randomUUID().toString(),
betId = participation.betId,
username = user.username,
username = user.id,
answer = participation.answer,
stake = participation.stake
)

Loading…
Cancel
Save