maj types entités & cors

This commit is contained in:
pedro 2025-06-03 10:05:40 +02:00
parent c644a1f2d5
commit fe9a7136fe
6 changed files with 40 additions and 33 deletions

View file

@ -7,6 +7,13 @@ import jakarta.persistence.Id
import jakarta.persistence.SequenceGenerator import jakarta.persistence.SequenceGenerator
import jakarta.persistence.Table import jakarta.persistence.Table
import jakarta.validation.constraints.* import jakarta.validation.constraints.*
import java.util.Date
enum class MatchState {
ONGOING,
FINISHED,
NOT_STARTED
}
@Entity @Entity
@Table(name="matches") @Table(name="matches")
@ -28,6 +35,6 @@ data class MatchBean(
var score1:Int=0, var score1:Int=0,
@field:Min(value = 0, message = "Score must be at least 0") @field:Min(value = 0, message = "Score must be at least 0")
var score2:Int=0, var score2:Int=0,
val date: String?=null, val date: Date?=null,
val state:String?=null val state: MatchState?=null
) )

View file

@ -7,6 +7,13 @@ import jakarta.persistence.Id
import jakarta.persistence.SequenceGenerator import jakarta.persistence.SequenceGenerator
import jakarta.persistence.Table import jakarta.persistence.Table
enum class RefereeLevel {
DEPARTMENTAL,
REGIONAL,
NATIONAL,
INTERNATIONAL
}
@Entity @Entity
@Table(name="referees") @Table(name="referees")
data class RefereeBean( data class RefereeBean(
@ -16,5 +23,5 @@ data class RefereeBean(
val id:Long?=null, val id:Long?=null,
val name:String?=null, val name:String?=null,
val firstName:String?=null, val firstName:String?=null,
val qualification:String?=null val level:RefereeLevel?=null
) )

View file

@ -1,12 +1,14 @@
package fr.teamflash.fencerjudgeback.restControllers package fr.teamflash.fencerjudgeback.restControllers
import fr.teamflash.fencerjudgeback.entities.MatchBean import fr.teamflash.fencerjudgeback.entities.MatchBean
import fr.teamflash.fencerjudgeback.restControllers.RefereeRestController.Companion.URL_ORIGIN import fr.teamflash.fencerjudgeback.entities.MatchState
import fr.teamflash.fencerjudgeback.services.MatchService import fr.teamflash.fencerjudgeback.services.MatchService
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
import java.util.Date
@RestController @RestController
@CrossOrigin(origins = ["*"])
@RequestMapping("/matches") @RequestMapping("/matches")
class MatchRestController(private val matchService: MatchService) { class MatchRestController(private val matchService: MatchService) {
@ -22,7 +24,7 @@ class MatchRestController(private val matchService: MatchService) {
// Lister tous les matchs à partir d'une certaine date // Lister tous les matchs à partir d'une certaine date
@GetMapping("/date/{date}") @GetMapping("/date/{date}")
fun getAllFromDate(@PathVariable date:String): ResponseEntity<List<MatchBean?>?> { fun getAllFromDate(@PathVariable date: Date): ResponseEntity<List<MatchBean?>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.date == date }) return ResponseEntity.ok(matchService.getAll().filter { it.date == date })
} }
@ -47,19 +49,19 @@ class MatchRestController(private val matchService: MatchService) {
// Lister les matchs en cours // Lister les matchs en cours
@GetMapping("/active") @GetMapping("/active")
fun getAllActive(): ResponseEntity<List<MatchBean>?> { fun getAllActive(): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.state == "ACTIVE" }) return ResponseEntity.ok(matchService.getAll().filter { it.state == MatchState.ONGOING })
} }
// Lister les matchs terminés // Lister les matchs terminés
@GetMapping("/over") @GetMapping("/over")
fun getAllFinished(): ResponseEntity<List<MatchBean>?> { fun getAllFinished(): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.state == "FINISHED" }) return ResponseEntity.ok(matchService.getAll().filter { it.state == MatchState.FINISHED })
} }
// Lister les matchs non commencés // Lister les matchs non commencés
@GetMapping("/not-started") @GetMapping("/not-started")
fun getAllNotStarted(): ResponseEntity<List<MatchBean>?> { fun getAllNotStarted(): ResponseEntity<List<MatchBean>?> {
return ResponseEntity.ok(matchService.getAll().filter { it.state == "NOT STARTED" }) return ResponseEntity.ok(matchService.getAll().filter { it.state == MatchState.NOT_STARTED })
} }
// Afficher un match par id // Afficher un match par id
@ -69,22 +71,18 @@ class MatchRestController(private val matchService: MatchService) {
} }
// Ajouter un match // Ajouter un match
@CrossOrigin(origins = [URL_ORIGIN])
@PostMapping("/create-match") @PostMapping("/create-match")
fun createMatch(@RequestBody match: MatchBean): ResponseEntity<MatchBean> { fun createMatch(@RequestBody match: MatchBean): ResponseEntity<MatchBean> {
// return ResponseEntity.status(HttpStatus.CREATED).body(matchService.createMatch(match))
return ResponseEntity.ok(matchService.createMatch(match)) return ResponseEntity.ok(matchService.createMatch(match))
} }
// Mettre à jour un match // Mettre à jour un match
@CrossOrigin(origins = [URL_ORIGIN])
@PutMapping("/update-match/{id}") @PutMapping("/update-match/{id}")
fun updateMatch(@PathVariable id: Long, @RequestBody match: MatchBean): ResponseEntity<Int> { fun updateMatch(@PathVariable id: Long, @RequestBody match: MatchBean): ResponseEntity<Int> {
return ResponseEntity.ok(matchService.updateMatch(id, match)) return ResponseEntity.ok(matchService.updateMatch(id, match))
} }
// Supprimer un match // Supprimer un match
@CrossOrigin(origins = [URL_ORIGIN])
@DeleteMapping("/delete-match/{id}") @DeleteMapping("/delete-match/{id}")
fun deleteMatch(@PathVariable id: Long): ResponseEntity<Int> { fun deleteMatch(@PathVariable id: Long): ResponseEntity<Int> {
return ResponseEntity.ok(matchService.deleteMatchById(id)) return ResponseEntity.ok(matchService.deleteMatchById(id))

View file

@ -1,7 +1,7 @@
package fr.teamflash.fencerjudgeback.restControllers package fr.teamflash.fencerjudgeback.restControllers
import fr.teamflash.fencerjudgeback.entities.PlayerBean import fr.teamflash.fencerjudgeback.entities.PlayerBean
import fr.teamflash.fencerjudgeback.restControllers.RefereeRestController.Companion.URL_ORIGIN import fr.teamflash.fencerjudgeback.restControllers.MatchRestController.Companion.URL_ORIGIN
import fr.teamflash.fencerjudgeback.services.PlayerService import fr.teamflash.fencerjudgeback.services.PlayerService
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.CrossOrigin import org.springframework.web.bind.annotation.CrossOrigin
@ -15,13 +15,10 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@CrossOrigin(origins = ["*"])
@RequestMapping("/players") @RequestMapping("/players")
class PlayerRestController(private val playerService: PlayerService) { class PlayerRestController(private val playerService: PlayerService) {
companion object {
const val URL_ORIGIN: String = "http://localhost:*"
}
// Lister tous les joueurs // Lister tous les joueurs
@GetMapping("/") @GetMapping("/")
fun getAll(): ResponseEntity<List<PlayerBean>> { fun getAll(): ResponseEntity<List<PlayerBean>> {

View file

@ -1,6 +1,8 @@
package fr.teamflash.fencerjudgeback.restControllers package fr.teamflash.fencerjudgeback.restControllers
import fr.teamflash.fencerjudgeback.entities.MatchState
import fr.teamflash.fencerjudgeback.entities.RefereeBean import fr.teamflash.fencerjudgeback.entities.RefereeBean
import fr.teamflash.fencerjudgeback.entities.RefereeLevel
import fr.teamflash.fencerjudgeback.services.RefereeService import fr.teamflash.fencerjudgeback.services.RefereeService
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.CrossOrigin import org.springframework.web.bind.annotation.CrossOrigin
@ -14,13 +16,10 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@CrossOrigin(origins = ["*"])
@RequestMapping("/referees") @RequestMapping("/referees")
class RefereeRestController(private val refereeService: RefereeService) { class RefereeRestController(private val refereeService: RefereeService) {
companion object {
const val URL_ORIGIN: String = "http://localhost:*"
}
// Lister tous les arbitres // Lister tous les arbitres
@GetMapping("/") @GetMapping("/")
fun getAll() : ResponseEntity<List<RefereeBean>> { fun getAll() : ResponseEntity<List<RefereeBean>> {
@ -45,28 +44,25 @@ class RefereeRestController(private val refereeService: RefereeService) {
return ResponseEntity.ok(refereeService.getByFirstName(firstName)) return ResponseEntity.ok(refereeService.getByFirstName(firstName))
} }
// Afficher un ou plusieurs arbitre(s) par qualification // Afficher un ou plusieurs arbitre(s) par niveau
@GetMapping("/qualification/{qualification}") @GetMapping("/level/{level}")
fun getByQualification(@PathVariable qualification:String): ResponseEntity<List<RefereeBean?>?> { fun getByQualification(@PathVariable level: RefereeLevel): ResponseEntity<List<RefereeBean?>?> {
return ResponseEntity.ok(refereeService.getByQualification(qualification)) return ResponseEntity.ok(refereeService.getByLevel(level))
} }
// Ajouter un arbitre // Ajouter un arbitre
@CrossOrigin(origins = [URL_ORIGIN])
@PostMapping("/create-referee") @PostMapping("/create-referee")
fun createReferee(@RequestBody referee: RefereeBean): ResponseEntity<RefereeBean> { fun createReferee(@RequestBody referee: RefereeBean): ResponseEntity<RefereeBean> {
return ResponseEntity.ok(refereeService.createReferee(referee)) return ResponseEntity.ok(refereeService.createReferee(referee))
} }
// Modifier un arbitre // Modifier un arbitre
@CrossOrigin(origins = [URL_ORIGIN])
@PutMapping("/update-referee/{id}") @PutMapping("/update-referee/{id}")
fun updateReferee(@PathVariable id: Long, @RequestBody referee: RefereeBean) : ResponseEntity<Int> { fun updateReferee(@PathVariable id: Long, @RequestBody referee: RefereeBean) : ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.updateReferee(id, referee)) return ResponseEntity.ok(refereeService.updateReferee(id, referee))
} }
// Supprimer un arbitre // Supprimer un arbitre
@CrossOrigin(origins = [URL_ORIGIN])
@DeleteMapping("/delete-referee/{id}") @DeleteMapping("/delete-referee/{id}")
fun deleteReferee(@PathVariable id:Long): ResponseEntity<Int> { fun deleteReferee(@PathVariable id:Long): ResponseEntity<Int> {
return ResponseEntity.ok(refereeService.deleteRefereeById(id)) return ResponseEntity.ok(refereeService.deleteRefereeById(id))

View file

@ -1,6 +1,8 @@
package fr.teamflash.fencerjudgeback.services package fr.teamflash.fencerjudgeback.services
import fr.teamflash.fencerjudgeback.entities.MatchState
import fr.teamflash.fencerjudgeback.entities.RefereeBean import fr.teamflash.fencerjudgeback.entities.RefereeBean
import fr.teamflash.fencerjudgeback.entities.RefereeLevel
import fr.teamflash.fencerjudgeback.repositories.RefereeRepository import fr.teamflash.fencerjudgeback.repositories.RefereeRepository
import fr.teamflash.fencerjudgeback.websocket.controllers.RefereeWebSocketController import fr.teamflash.fencerjudgeback.websocket.controllers.RefereeWebSocketController
import fr.teamflash.fencerjudgeback.websocket.models.RefereeUpdateMessage import fr.teamflash.fencerjudgeback.websocket.models.RefereeUpdateMessage
@ -42,10 +44,10 @@ class RefereeService(
return refereeRepository.findAll().filter{ it.firstName == firstName } return refereeRepository.findAll().filter{ it.firstName == firstName }
} }
// Obtenir un ou plusieurs arbitre(s) par qualification // Obtenir un ou plusieurs arbitre(s) par niveau
fun getByQualification(qualification:String): List<RefereeBean?>? { fun getByLevel(level: RefereeLevel): List<RefereeBean>? {
println("RefereeService.getRefereeByQualification : $qualification") println("RefereeService.getByLevel : $level")
return refereeRepository.findAll().filter{ it.qualification == qualification } return refereeRepository.findAll().filter{ it.level == level }
} }
// Ajouter un arbitre (admin) // Ajouter un arbitre (admin)