From 0f90a233a6af24cdf90a402b7806d4f791bd9f0c Mon Sep 17 00:00:00 2001 From: pedro Date: Tue, 3 Jun 2025 14:23:07 +0200 Subject: [PATCH] update match scores function --- .../restControllers/MatchRestController.kt | 7 +++++++ .../fencerjudgeback/services/MatchService.kt | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt index 9d526ac..c8bfaf2 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt @@ -6,6 +6,7 @@ import fr.teamflash.fencerjudgeback.services.MatchService import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import java.util.Date +import java.util.Dictionary @RestController @CrossOrigin(origins = ["*"]) @@ -82,6 +83,12 @@ class MatchRestController(private val matchService: MatchService) { return ResponseEntity.ok(matchService.updateMatch(id, match)) } + // Mettre à jour les scores d'un match + @PutMapping("/update-match-scores/{id}") + fun updateMatchScores(@PathVariable id: Long, @RequestBody score1:Int, @RequestBody score2:Int): ResponseEntity { + return ResponseEntity.ok(matchService.updateScores(id, score1, score2)) + } + // Supprimer un match @DeleteMapping("/delete-match/{id}") fun deleteMatch(@PathVariable id: Long): ResponseEntity { diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt index 1e5f24b..383bbd4 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt @@ -61,6 +61,21 @@ class MatchService( return 1 } + // Modifier le score d'un match (admin) + fun updateScores(id:Long?, score1:Int, score2:Int): Int { + println("MatchService.updateScores : $id - $score1 - $score2") + if (getById(id) == null) { + return -1 + } + + val match = getById(id) + match?.score1 = score1 + match?.score2 = score2 + match?.let { matchRepository.save(it) } + + return 1 + } + // Supprimer un match (admin) fun deleteMatchById(id: Long?) : Int? { println("MatchService.deleteMatchById : $id")