Add UserDTO information (number of friends, number of bets and the best win)
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

pull/17/head
luevard 8 months ago
parent 9069432225
commit 5229765d6b

@ -7,4 +7,5 @@ interface ParticipationDataSource {
fun getParticipationFromBetId(betid: String): List<Participation>
fun getParticipationFromUserId(username: String, betid: String): List<Participation>
fun deleteParticipation(id: String): Boolean
fun getBestWinFromUserid(userId: String): Int?
}

@ -81,4 +81,8 @@ class MockParticipationDataSource(private val mockData: MockDataSource.MockData)
return result
}
override fun getBestWinFromUserid(userId: String) =
mockData.participations.filter { it.id == userId }.maxBy { it.stake }.stake
}

@ -18,7 +18,10 @@ class MockUserDataSource(private val mockData: MockDataSource.MockData) : UserDa
email = it.email,
nbCoins = it.nbCoins,
token = it.token,
image = null
image = null,
nbBets = MockBetDataSource(mockData).getHistory(it.username).count(),
nbFriends = MockFriendDataSource(mockData).getFriendFromUserId(it.id).count(),
bestWin = MockParticipationDataSource(mockData).getBestWinFromUserid(it.id)
),
it.password
)
@ -58,15 +61,21 @@ class MockUserDataSource(private val mockData: MockDataSource.MockData) : UserDa
}
override fun addImage(userid: String, image: ByteArray) {
TODO("Not yet implemented")
val user = users.find { it.id == userid }
if (user != null) {
user.image = image.toString()
}
}
override fun removeImage(userid: String) {
TODO("Not yet implemented")
val user = users.find { it.id == userid }
if (user != null) {
user.image = null
}
}
override fun getImage(userid: String): String? {
TODO("Not yet implemented")
return users.find { it.id == userid }?.image
}
}

@ -64,5 +64,10 @@ class PostgresParticipationDataSource(private val database: Database) : Particip
}
return participation.delete() > 0
}
override fun getBestWinFromUserid(userId: String) =
database.participations.filter { it.id eq userId }.maxBy { it.stake }
}

@ -92,12 +92,8 @@ class PostgresUserDataSource(private val database: Database) : UserDataSource {
database.usersimage.removeIf { it.id eq userid }
}
/*override fun getImage(userid: String): ByteArray? =
database.usersimage.find { it.id eq userid }?.image*/
override fun getImage(userid: String): String? {
val resultSet = database.executeWithResult("SELECT encode(image, 'base64') AS image FROM userimage WHERE user_id = '${userid}'")?: return null
if (resultSet.next()) {
val base64Image: String? = resultSet.getString("image")
if (base64Image != null) {

@ -1,5 +1,8 @@
package allin.data.postgres.entities
import allin.data.postgres.PostgresBetDataSource
import allin.data.postgres.PostgresFriendDataSource
import allin.data.postgres.PostgresParticipationDataSource
import allin.dto.UserDTO
import allin.routing.imageManagerUser
import allin.utils.AppConfig
@ -31,7 +34,10 @@ interface UserEntity : Entity<UserEntity> {
email = email,
nbCoins = nbCoins,
token = null,
image = getImage(id, database)
image = getImage(id, database),
nbBets = PostgresBetDataSource(database).getHistory(username).count(),
nbFriends = PostgresFriendDataSource(database).getFriendFromUserId(id).count(),
bestWin = PostgresParticipationDataSource(database).getBestWinFromUserid(id)?: 0,
)
fun getImage(userId: String, database: Database): String? {

@ -9,5 +9,8 @@ data class UserDTO(
val email: String,
val nbCoins: Int,
var token: String?,
val image: String?
val image: String?,
var nbBets: Int,
var nbFriends: Int,
var bestWin: Int
)

@ -13,7 +13,8 @@ data class User(
val email: String,
var password: String,
var nbCoins: Int = DEFAULT_COIN_AMOUNT,
var token: String? = null
var token: String? = null,
var image: String? = null,
)
@Serializable

Loading…
Cancel
Save