jpe-controle/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/restControllers/RefereeRestController.kt
2025-06-03 10:05:40 +02:00

71 lines
2.8 KiB
Kotlin

package fr.teamflash.fencerjudgeback.restControllers
import fr.teamflash.fencerjudgeback.entities.MatchState
import fr.teamflash.fencerjudgeback.entities.RefereeBean
import fr.teamflash.fencerjudgeback.entities.RefereeLevel
import fr.teamflash.fencerjudgeback.services.RefereeService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.CrossOrigin
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.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@CrossOrigin(origins = ["*"])
@RequestMapping("/referees")
class RefereeRestController(private val refereeService: RefereeService) {
// Lister tous les arbitres
@GetMapping("/")
fun getAll() : ResponseEntity<List<RefereeBean>> {
return ResponseEntity.ok(refereeService.getAll())
}
// Afficher un arbitre par id
@GetMapping("/{id}")
fun getById(@PathVariable id: Long): ResponseEntity<RefereeBean?> {
return ResponseEntity.ok(refereeService.getById(id))
}
// Afficher un ou plusieurs arbitre(s) par nom
@GetMapping("/name/{name}")
fun getByName(@PathVariable name:String): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByName(name))
}
// Afficher un ou plusieurs arbitre(s) par prénom
@GetMapping("/firstname/{firstName}")
fun getByFirstName(@PathVariable firstName:String): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByFirstName(firstName))
}
// Afficher un ou plusieurs arbitre(s) par niveau
@GetMapping("/level/{level}")
fun getByQualification(@PathVariable level: RefereeLevel): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByLevel(level))
}
// Ajouter un arbitre
@PostMapping("/create-referee")
fun createReferee(@RequestBody referee: RefereeBean): ResponseEntity<RefereeBean> {
return ResponseEntity.ok(refereeService.createReferee(referee))
}
// Modifier un arbitre
@PutMapping("/update-referee/{id}")
fun updateReferee(@PathVariable id: Long, @RequestBody referee: RefereeBean) : ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.updateReferee(id, referee))
}
// Supprimer un arbitre
@DeleteMapping("/delete-referee/{id}")
fun deleteReferee(@PathVariable id:Long): ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.deleteRefereeById(id))
}
}