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.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("/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(@PathVariable id: Long): ResponseEntity { return ResponseEntity.ok(playerService.getById(id)) } // Afficher un ou plusieurs joueur(s) par nom @GetMapping("/name/{name}") fun getByName(@PathVariable name: String): ResponseEntity?> { return ResponseEntity.ok(playerService.getByName(name)) } // Afficher un ou plusieurs joueur(s) par prénom @GetMapping("/firstName/{firstName}") fun getByFirstName(@PathVariable firstName: String): ResponseEntity?> { return ResponseEntity.ok(playerService.getByFirstName(firstName)) } // Afficher un ou plusieurs joueur(s) par club @GetMapping("/club/{club}") fun getByClub(@PathVariable club: String): ResponseEntity?> { return ResponseEntity.ok(playerService.getByClub(club)) } // Ajouter un joueur @PostMapping("/create-player") fun createPlayer(@RequestBody player: PlayerBean): ResponseEntity { return ResponseEntity.ok(playerService.createPlayer(player)) } // Modifier un joueur @PutMapping("/update-player/{id}") fun updatePlayer(@PathVariable id: Long, @RequestBody player: PlayerBean): ResponseEntity { return ResponseEntity.ok(playerService.updatePlayer(id, player)) } // Supprimer un joueur @DeleteMapping("/delete-player/{id}") fun deletePlayer(@PathVariable id: Long): ResponseEntity { return ResponseEntity.ok(playerService.deletePlayerById(id)) } }