restcontrollers à faire

This commit is contained in:
pedro 2025-06-02 08:53:13 +02:00
parent f37b021c7c
commit cf9c196053
3 changed files with 171 additions and 7 deletions

View file

@ -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) {
// Lister tous les matchs
@GetMapping("/")
fun getAll(): ResponseEntity<List<MatchBean>> {
return ResponseEntity.ok(matchService.getAll())
}
// Lister tous les matchs à partir d'une certaine date
@GetMapping("/{date}")
fun getAllFromDate(date:Date): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.date == date })
}
// Lister les matchs en cours
@GetMapping("/active")
fun getAllActive(): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.state == ACTIVE })
}
// Lister les matchs terminés
@GetMapping("/over")
fun getAllFinished(): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { })
}
// Lister les matchs non commencés
@GetMapping("/not-started")
fun getAllNotStarted(): ResponseEntity<List<MatchBean>?> {
}
// Afficher un match par id
@GetMapping("/{id}")
fun getMatchById(@PathVariable id: Long): ResponseEntity<MatchBean?> {
return ResponseEntity.ok(matchService.getById(id))
}
// Ajouter un match
@PostMapping("/create-match")
fun createMatch(@RequestBody match: MatchBean): ResponseEntity<MatchBean> {
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<MatchBean?> {
return ResponseEntity.ok(matchService.updateMatch(match))
}
// Supprimer un match
@DeleteMapping("/delete-match/{id}")
fun deleteMatch(@PathVariable id: Long): ResponseEntity<Int> {
return ResponseEntity.ok(matchService.deleteMatch(id))
}
}

View file

@ -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 {
@RequestMapping("/players")
class PlayerRestController(private val playerService: PlayerService) {
// Lister tous les joueurs
@GetMapping
fun getAll(): ResponseEntity<List<PlayerBean>> {
return ResponseEntity.ok(playerService.getAll())
}
// Afficher un joueur par id
@GetMapping("/{id}")
fun getById(id: Long): ResponseEntity<Optional<PlayerBean?>?> {
return ResponseEntity.ok(playerService.getById(id))
}
// Afficher un joueur par nom
@GetMapping("/{name}")
fun getByName(name: String): ResponseEntity<List<PlayerBean?>?> {
return ResponseEntity.ok(playerService.getByName(name))
}
// Afficher un joueur par prénom
@GetMapping("/{firstName}")
fun getByFirstName(firstName: String): ResponseEntity<List<PlayerBean?>?> {
return ResponseEntity.ok(playerService.getByFirstName(firstName))
}
// Ajouter un joueur
@PostMapping("/add-player")
fun createPlayer(player: PlayerBean): ResponseEntity<PlayerBean> {
return ResponseEntity.ok(playerService.createPlayer(player))
}
// Modifier un joueur
@PutMapping("/update-player")
fun updatePlayer(id: Long, name: String, firstName: String): ResponseEntity<Int> {
return ResponseEntity.ok(playerService.updatePlayer(id, name, firstName))
}
// Supprimer un joueur
@DeleteMapping("/delete-player")
fun deletePlayer(id: Long): ResponseEntity<Int> {
return ResponseEntity.ok(playerService.deletePlayer(id))
}
}

View file

@ -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) {
// Lister tous les arbitres
@GetMapping("/")
fun getAll() : ResponseEntity<List<RefereeBean>> {
return ResponseEntity.ok(refereeService.getAll())
}
// Afficher un arbitre par id
@GetMapping("/{id}")
fun getById(id: Long): ResponseEntity<Optional<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getById(id))
}
// Afficher un ou plusieurs arbitre(s) par nom
@GetMapping("/name/{name}")
fun getByName(name:String): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByName(name))
}
// Afficher ou plusieurs arbitre(s) par prénom
@GetMapping("/first-name/{firstName}")
fun getByFirstName(firstName:String): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByFirstName(firstName))
}
// Ajouter un arbitre
@PostMapping("/create-referee")
fun createReferee(referee: RefereeBean): ResponseEntity<RefereeBean> {
return ResponseEntity.ok(refereeService.createReferee(referee))
}
// Modifier un arbitre
@PutMapping("/update-referee/{id}")
fun updateReferee(@PathVariable id: Long, name: String, firstName: String) : ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.updateReferee(id, name, firstName))
}
// Supprimer un arbitre
@DeleteMapping("/delete-referee/{id}")
fun deleteReferee(id:Long): ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.deleteReferee(id))
}
}