package fr.teamflash.fencerjudgeback.restControllers import fr.teamflash.fencerjudgeback.entities.MatchBean import fr.teamflash.fencerjudgeback.services.MatchService import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/matches") class MatchRestController(private val matchService: MatchService) { // Lister tous les matchs @GetMapping("/") fun getAll(): ResponseEntity?> { return ResponseEntity.ok(matchService.getAll()) } // Lister tous les matchs à partir d'une certaine date @GetMapping("/date/{date}") fun getAllFromDate(@PathVariable date:String): ResponseEntity?> { return ResponseEntity.ok(matchService.getAll().filter { it.date == date }) } // Lister tous les matchs par pays @GetMapping("/country/{country}") fun getAllFromCountry(@PathVariable country:String): ResponseEntity?> { return ResponseEntity.ok(matchService.getAll().filter { it.country == country }) } // Lister tous les matchs par ville @GetMapping("/city/{city}") fun getAllFromCity(@PathVariable city:String): ResponseEntity?> { return ResponseEntity.ok(matchService.getAll().filter { it.city == city }) } // Lister tous les matchs par joueurs @GetMapping("/players/{player1ID}/{player2ID}") fun getAllWithPlayers(@PathVariable player1ID: Long?, @PathVariable player2ID: Long?): ResponseEntity?> { return ResponseEntity.ok(matchService.getByPlayers(player1ID, player2ID)) } // 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 { it.state == "FINISHED" }) } // Lister les matchs non commencés @GetMapping("/not-started") fun getAllNotStarted(): ResponseEntity?> { return ResponseEntity.ok(matchService.getAll().filter { it.state == "NOT STARTED" }) } // Afficher un match par id @GetMapping("/{id}") fun getById(@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)) return ResponseEntity.ok(matchService.createMatch(match)) } // Mettre à jour un match @PutMapping("/update-match/{id}") fun updateMatch(@PathVariable id: Long, @RequestBody match: MatchBean): ResponseEntity { return ResponseEntity.ok(matchService.updateMatch(id, match)) } // Supprimer un match @DeleteMapping("/delete-match/{id}") fun deleteMatch(@PathVariable id: Long): ResponseEntity { return ResponseEntity.ok(matchService.deleteMatchById(id)) } }