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 get() = allInDataSource
fun main() { fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") { embeddedServer(Netty, port = 10001, host = "0.0.0.0") {
extracted() extracted()
}.start(wait = true) }.start(wait = true)
} }

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save