From a395c753dc9a2f6ad4ef772e96976eca7c018522 Mon Sep 17 00:00:00 2001 From: luevard <99143550+saucepommefrite@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:40:30 +0200 Subject: [PATCH] :sparkles: Patch BetDetail when it has 0 participation --- .../allin/data/postgres/entities/BetEntity.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/src/main/kotlin/allin/data/postgres/entities/BetEntity.kt b/Sources/src/main/kotlin/allin/data/postgres/entities/BetEntity.kt index be14550..8216e88 100644 --- a/Sources/src/main/kotlin/allin/data/postgres/entities/BetEntity.kt +++ b/Sources/src/main/kotlin/allin/data/postgres/entities/BetEntity.kt @@ -58,20 +58,25 @@ interface BetEntity : Entity { .filter { it.betId eq bet.id } .map { it.toBetAnswerInfo() } - return BetDetail( + val betD = BetDetail( bet = bet, answers = getBetAnswerDetail(bet, participationEntities, answerInfos), participations = participationEntities, userParticipation = userParticipation?.toParticipation(database), - wonParticipation = if (bet.status == BetStatus.FINISHED) { - val result = database.betResults.find { it.betId eq this.id } - result?.let { r -> + wonParticipation = if (participationEntities.isEmpty()) { + null + } else if (bet.status == BetStatus.FINISHED) { + database.betResults.find { it.betId eq this.id }?.let { r -> participationEntities .filter { it.answer == r.result } .maxBy { it.stake } } } else null ) + + + return betD + } }