From cf9c196053152fbdb97ab7f99537417527c7a264 Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 2 Jun 2025 08:53:13 +0200 Subject: [PATCH] =?UTF-8?q?restcontrollers=20=C3=A0=20faire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restControllers/MatchRestController.kt | 65 ++++++++++++++++++- .../restControllers/PlayerRestController.kt | 56 +++++++++++++++- .../restControllers/RefereeRestController.kt | 57 +++++++++++++++- 3 files changed, 171 insertions(+), 7 deletions(-) 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 89b6779..1775fc4 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/MatchRestController.kt @@ -1,8 +1,67 @@ package fr.teamflash.fencerjudgeback.restControllers -import org.springframework.web.bind.annotation.RestController +import fr.teamflash.fencerjudgeback.entities.MatchBean +import fr.teamflash.fencerjudgeback.services.MatchService +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.* +import kotlin.random.Random @RestController -class MatchRestController { +@RequestMapping("/matches") +class MatchRestController(private val matchService: MatchService) { -} \ No newline at end of file + // Lister tous les matchs + @GetMapping("/") + fun getAll(): ResponseEntity> { + return ResponseEntity.ok(matchService.getAll()) + } + + // Lister tous les matchs à partir d'une certaine date + @GetMapping("/{date}") + fun getAllFromDate(date:Date): ResponseEntity?> { + return ResponseEntity.ok(matchService.getAll().filter { it.date == date }) + } + + // Lister les matchs en cours + @GetMapping("/active") + fun getAllActive(): ResponseEntity?> { + return ResponseEntity.ok(matchService.getAll().filter { it.state == ACTIVE }) + } + + // Lister les matchs terminés + @GetMapping("/over") + fun getAllFinished(): ResponseEntity?> { + return ResponseEntity.ok(matchService.getAll().filter { }) + } + + // Lister les matchs non commencés + @GetMapping("/not-started") + fun getAllNotStarted(): ResponseEntity?> { + + } + + // Afficher un match par id + @GetMapping("/{id}") + fun getMatchById(@PathVariable id: Long): ResponseEntity { + return ResponseEntity.ok(matchService.getById(id)) + } + + // Ajouter un match + @PostMapping("/create-match") + fun createMatch(@RequestBody match: MatchBean): ResponseEntity { + return ResponseEntity.status(HttpStatus.CREATED).body(matchService.createMatch(match)) + } + + // Mettre à jour un match + @PutMapping("/update-match/{id}") + fun updateMatch(@PathVariable id: Long, @RequestBody refereeID: Long, @RequestBody): ResponseEntity { + return ResponseEntity.ok(matchService.updateMatch(match)) + } + + // Supprimer un match + @DeleteMapping("/delete-match/{id}") + fun deleteMatch(@PathVariable id: Long): ResponseEntity { + return ResponseEntity.ok(matchService.deleteMatch(id)) + } +} diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/PlayerRestController.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/PlayerRestController.kt index b6ea5c9..a32d39b 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/PlayerRestController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/PlayerRestController.kt @@ -1,7 +1,59 @@ package fr.teamflash.fencerjudgeback.restControllers +import fr.teamflash.fencerjudgeback.entities.PlayerBean +import fr.teamflash.fencerjudgeback.services.PlayerService +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import java.util.Optional @RestController -class PlayerRestController { -} \ No newline at end of file +@RequestMapping("/players") +class PlayerRestController(private val playerService: PlayerService) { + + // Lister tous les joueurs + @GetMapping + fun getAll(): ResponseEntity> { + return ResponseEntity.ok(playerService.getAll()) + } + + // Afficher un joueur par id + @GetMapping("/{id}") + fun getById(id: Long): ResponseEntity?> { + return ResponseEntity.ok(playerService.getById(id)) + } + + // Afficher un joueur par nom + @GetMapping("/{name}") + fun getByName(name: String): ResponseEntity?> { + return ResponseEntity.ok(playerService.getByName(name)) + } + + // Afficher un joueur par prénom + @GetMapping("/{firstName}") + fun getByFirstName(firstName: String): ResponseEntity?> { + return ResponseEntity.ok(playerService.getByFirstName(firstName)) + } + + // Ajouter un joueur + @PostMapping("/add-player") + fun createPlayer(player: PlayerBean): ResponseEntity { + return ResponseEntity.ok(playerService.createPlayer(player)) + } + + // Modifier un joueur + @PutMapping("/update-player") + fun updatePlayer(id: Long, name: String, firstName: String): ResponseEntity { + return ResponseEntity.ok(playerService.updatePlayer(id, name, firstName)) + } + + // Supprimer un joueur + @DeleteMapping("/delete-player") + fun deletePlayer(id: Long): ResponseEntity { + return ResponseEntity.ok(playerService.deletePlayer(id)) + } +} diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/RefereeRestController.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/RefereeRestController.kt index 99c20b9..01216cc 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/RefereeRestController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/RefereeRestController.kt @@ -1,8 +1,61 @@ package fr.teamflash.fencerjudgeback.restControllers +import fr.teamflash.fencerjudgeback.entities.RefereeBean +import fr.teamflash.fencerjudgeback.services.RefereeService +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import java.util.Optional @RestController -class RefereeRestController { +@RequestMapping("/referees") +class RefereeRestController(private val refereeService: RefereeService) { -} \ No newline at end of file + // Lister tous les arbitres + @GetMapping("/") + fun getAll() : ResponseEntity> { + return ResponseEntity.ok(refereeService.getAll()) + } + + // Afficher un arbitre par id + @GetMapping("/{id}") + fun getById(id: Long): ResponseEntity?> { + return ResponseEntity.ok(refereeService.getById(id)) + } + + // Afficher un ou plusieurs arbitre(s) par nom + @GetMapping("/name/{name}") + fun getByName(name:String): ResponseEntity?> { + return ResponseEntity.ok(refereeService.getByName(name)) + } + + // Afficher ou plusieurs arbitre(s) par prénom + @GetMapping("/first-name/{firstName}") + fun getByFirstName(firstName:String): ResponseEntity?> { + return ResponseEntity.ok(refereeService.getByFirstName(firstName)) + } + + // Ajouter un arbitre + @PostMapping("/create-referee") + fun createReferee(referee: RefereeBean): ResponseEntity { + return ResponseEntity.ok(refereeService.createReferee(referee)) + } + + // Modifier un arbitre + @PutMapping("/update-referee/{id}") + fun updateReferee(@PathVariable id: Long, name: String, firstName: String) : ResponseEntity { + return ResponseEntity.ok(refereeService.updateReferee(id, name, firstName)) + } + + // Supprimer un arbitre + @DeleteMapping("/delete-referee/{id}") + fun deleteReferee(id:Long): ResponseEntity { + return ResponseEntity.ok(refereeService.deleteReferee(id)) + } + +}