✨ Local Database link
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
73841170cc
commit
ff4e36beea
@ -1,15 +1,4 @@
|
|||||||
package allin.dto
|
package allin.dto
|
||||||
|
|
||||||
import allin.model.User
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class UserDTO(val username: String,val email: String, val nbCoins: Int)
|
data class UserDTO(val username: String, val email: String, val nbCoins: Double, var token:String?)
|
||||||
@Serializable
|
|
||||||
data class UserDTOWithToken(val username: String,val email: String, val nbCoins: Int, val token:String?)
|
|
||||||
fun convertUserToUserDTO(user: User): UserDTO {
|
|
||||||
return UserDTO(user.username, user.email, user.nbCoins)
|
|
||||||
}
|
|
||||||
fun convertUserToUserDTOToken(user: User): UserDTOWithToken {
|
|
||||||
return UserDTOWithToken(user.username, user.email, user.nbCoins,user.token)
|
|
||||||
}
|
|
||||||
|
@ -1,12 +1,71 @@
|
|||||||
package allin.entities
|
package allin.entities
|
||||||
|
|
||||||
|
import allin.dto.UserDTO
|
||||||
|
import allin.model.User
|
||||||
|
import allin.routing.database
|
||||||
|
import org.ktorm.dsl.*
|
||||||
|
import org.ktorm.entity.*
|
||||||
import org.ktorm.schema.Table
|
import org.ktorm.schema.Table
|
||||||
import org.ktorm.schema.double
|
import org.ktorm.schema.double
|
||||||
import org.ktorm.schema.int
|
import org.ktorm.schema.int
|
||||||
import org.ktorm.schema.varchar
|
import org.ktorm.schema.varchar
|
||||||
object UserEntity : Table<Nothing>("utilisateur") {
|
|
||||||
|
interface UserEntity : Entity<UserEntity> {
|
||||||
|
val username: String
|
||||||
|
var email: String
|
||||||
|
var password: String
|
||||||
|
var nbCoins: Double
|
||||||
|
}
|
||||||
|
object UsersEntity : Table<UserEntity>("utilisateur") {
|
||||||
val id = int("id").primaryKey()
|
val id = int("id").primaryKey()
|
||||||
val username = varchar("username")
|
val username = varchar("username")
|
||||||
val password = varchar("password")
|
val password = varchar("password")
|
||||||
val nbCoins = double("nbCoins")
|
val nbCoins = double("nbCoins")
|
||||||
}
|
val email = varchar("email")
|
||||||
|
|
||||||
|
fun getUserToUserDTO(): MutableList<UserDTO> {
|
||||||
|
return database.from(UsersEntity).select().map {
|
||||||
|
row -> UserDTO(
|
||||||
|
row[username].toString(),
|
||||||
|
row[email].toString(),
|
||||||
|
row[nbCoins]?:0.0,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}.toMutableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getUserByUsernameAndPassword(login: String): Pair<UserDTO?, String?> {
|
||||||
|
return database.from(UsersEntity)
|
||||||
|
.select()
|
||||||
|
.where { (username eq login) /*and (password eq passwordParam)*/ }
|
||||||
|
.map { row ->
|
||||||
|
Pair(
|
||||||
|
UserDTO(
|
||||||
|
row[username].toString(),
|
||||||
|
row[email].toString(),
|
||||||
|
row[nbCoins] ?: 0.0,
|
||||||
|
null
|
||||||
|
),
|
||||||
|
row[password].toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.firstOrNull() ?: Pair(null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addUserEntity(user : User){
|
||||||
|
database.insert(UsersEntity){
|
||||||
|
set(it.nbCoins,user.nbCoins)
|
||||||
|
set(it.username,user.username)
|
||||||
|
set(it.password,user.password)
|
||||||
|
set(it.email,user.email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun deleteUserByUsername(username: String): Boolean {
|
||||||
|
val deletedCount = database.delete(UsersEntity) {
|
||||||
|
it.username eq username
|
||||||
|
}
|
||||||
|
return deletedCount > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
package allin.model
|
package allin.model
|
||||||
|
|
||||||
import allin.dto.UserDTOWithToken
|
import allin.serializer.ZonedDateTimeSerializer
|
||||||
import allin.serializer.DateSerializer
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Bet(val id: Int, val theme: String, val sentenceBet: String, @Serializable(DateSerializer::class) val endRegistration: Date, @Serializable(DateSerializer::class) var endBet : Date, var isPrivate : Boolean, var response : MutableList<String>, val createdBy : String)
|
data class Bet(val id: Int, val theme: String, val sentenceBet: String, @Serializable(ZonedDateTimeSerializer::class) val endRegistration: Date, @Serializable(ZonedDateTimeSerializer::class) var endBet : Date, var isPrivate : Boolean, var response : MutableList<String>, var createdBy : String)
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class UpdatedBetData(val id: Int,@Serializable(DateSerializer::class) val endBet: Date, val isPrivate: Boolean, val response: MutableList<String>)
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BetWithoutId(val theme: String, val sentenceBet: String, @Serializable(DateSerializer::class) val endRegistration: Date, @Serializable(DateSerializer::class) var endBet : Date, var isPrivate : Boolean, var response : MutableList<String>, val createdBy : String)
|
data class UpdatedBetData(val id: Int,@Serializable(ZonedDateTimeSerializer::class) val endBet: Date, val isPrivate: Boolean, val response: MutableList<String>)
|
||||||
|
|
||||||
fun convertBetWithoutIdToBet(betWithoutId: BetWithoutId,id : Int, username : String): Bet {
|
|
||||||
return Bet(id,betWithoutId.theme,betWithoutId.sentenceBet,betWithoutId.endRegistration, betWithoutId.endBet, betWithoutId.isPrivate, betWithoutId.response, username)
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
package allin.model
|
package allin.model
|
||||||
|
|
||||||
import allin.dto.UserDTOWithToken
|
import allin.dto.UserDTO
|
||||||
data class BetAction(val id:Int, val coins: Int, val user: String, val bet: Int)
|
data class BetAction(val id:Int, val coins: Int, val user: String, val bet: Int)
|
||||||
data class BetActionCompleted(val id:Int, val coins: Int, val user: UserDTOWithToken, val bet: Bet)
|
data class BetActionCompleted(val id:Int, val coins: Int, val user: UserDTO, val bet: Bet)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package allin.model
|
package allin.model
|
||||||
|
|
||||||
import allin.dto.UserDTO
|
|
||||||
import allin.routing.users
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class User(val username: String, val email: String, var password: String, var nbCoins: Int = 1000, var token: String? = null)
|
data class User(val username: String, val email: String, var password: String, var nbCoins: Double = 1000.0, var token: String? = null)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class CheckUser(val login: String,val password: String)
|
data class CheckUser(val login: String,val password: String)
|
||||||
|
Loading…
Reference in new issue