diff --git a/db/v-2/tables/lnk-contest-project.xml b/db/v-2/tables/lnk-contest-project.xml index 71bd4eab35..220bd7ad15 100644 --- a/db/v-2/tables/lnk-contest-project.xml +++ b/db/v-2/tables/lnk-contest-project.xml @@ -76,4 +76,10 @@ onDelete="CASCADE"/> + + + + + + \ No newline at end of file diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/LnkContestProjectService.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/LnkContestProjectService.kt index 23a472313e..12602371ba 100644 --- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/LnkContestProjectService.kt +++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/LnkContestProjectService.kt @@ -57,7 +57,7 @@ class LnkContestProjectService( * @return best score of [project] under [Contest] with name [contestName] */ fun getBestScoreOfProjectInContestWithName(project: Project, contestName: String) = - lnkContestProjectRepository.findByProjectAndContestName(project, contestName)?.bestScore + lnkContestProjectRepository.findByProjectAndContestName(project, contestName)?.bestExecution?.score /** * @param project a [Project] @@ -68,7 +68,7 @@ class LnkContestProjectService( fun saveLnkContestProject(project: Project, contest: Contest): Boolean = if (lnkContestProjectRepository.findByContestAndProject(contest, project).isPresent) { false } else { - lnkContestProjectRepository.save(LnkContestProject(project, contest, null, 0.0)) + lnkContestProjectRepository.save(LnkContestProject(project, contest, null)) true } @@ -87,7 +87,7 @@ class LnkContestProjectService( .orElseThrow { IllegalStateException("Project ${project.shortToString()} is not bound to contest name=${contest.name}") } - val oldBestScore = lnkContestProject.bestScore + val oldBestScore = lnkContestProject.bestExecution?.score if (oldBestScore == null || oldBestScore <= newScore) { logger.debug { "For project ${project.shortToString()} updating best_score from execution " + @@ -95,7 +95,6 @@ class LnkContestProjectService( "[id=${newExecution.id},score=$newScore]" } lnkContestProject.bestExecution = newExecution - lnkContestProject.bestScore = newExecution.score lnkContestProjectRepository.save(lnkContestProject) updateProjectContestRating(project) @@ -104,7 +103,7 @@ class LnkContestProjectService( private fun updateProjectContestRating(project: Project) { val projectContestRating = lnkContestProjectRepository.findByProject(project).mapNotNull { - it.bestScore + it.bestExecution?.score }.sum() projectService.updateProject(project.apply { diff --git a/save-backend/src/test/kotlin/com/saveourtool/save/backend/service/LnkContestProjectServiceTest.kt b/save-backend/src/test/kotlin/com/saveourtool/save/backend/service/LnkContestProjectServiceTest.kt index 82460f235e..315b087c2e 100644 --- a/save-backend/src/test/kotlin/com/saveourtool/save/backend/service/LnkContestProjectServiceTest.kt +++ b/save-backend/src/test/kotlin/com/saveourtool/save/backend/service/LnkContestProjectServiceTest.kt @@ -36,7 +36,7 @@ class LnkContestProjectServiceTest { then(lnkContestProjectRepository) .should(times(1)) .save(argWhere { - abs(it.bestScore!! - 4.0) < 1e-4 + abs(it.bestExecution?.score!! - 4.0) < 1e-4 }) } @@ -54,7 +54,7 @@ class LnkContestProjectServiceTest { then(lnkContestProjectRepository) .should(times(1)) .save(argWhere { - abs(it.bestScore!! - 4.0) < 1e-4 + abs(it.bestExecution?.score!! - 4.0) < 1e-4 }) } @@ -80,7 +80,7 @@ class LnkContestProjectServiceTest { @Suppress("PARAMETER_NAME_IN_OUTER_LAMBDA") given(lnkContestProjectRepository.findByContestAndProject(any(), any())) .willAnswer { - LnkContestProject(it.arguments[1] as Project, it.arguments[0] as Contest, oldBestExecution, oldBestExecution?.score) + LnkContestProject(it.arguments[1] as Project, it.arguments[0] as Contest, oldBestExecution) .let { Optional.of(it) } } } diff --git a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/LnkContestProject.kt b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/LnkContestProject.kt index 8805a00681..84f290afa0 100644 --- a/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/LnkContestProject.kt +++ b/save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/LnkContestProject.kt @@ -10,7 +10,6 @@ import javax.persistence.OneToOne * @property project * @property contest * @property bestExecution - * @property bestScore */ @Entity class LnkContestProject( @@ -25,9 +24,6 @@ class LnkContestProject( @OneToOne @JoinColumn(name = "best_execution_id") var bestExecution: Execution?, - - var bestScore: Double?, - ) : BaseEntity() { /** * Get [ContestResult]