entités, services et restcontrollers fonctionnels; websocket à intégrer
This commit is contained in:
parent
cf9c196053
commit
1d97283343
13 changed files with 332 additions and 135 deletions
|
|
@ -2,3 +2,5 @@ corriger les services - ~
|
|||
tester les restcontrollers via des requêtes http - ~
|
||||
créer la bdd avec toutes les tables (repositories)
|
||||
tester le websocket
|
||||
prévoir l'utilisation en admin uniquement (spring security)
|
||||
faire le jackarta de l'api
|
||||
|
|
@ -27,13 +27,16 @@ dependencies {
|
|||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
|
||||
// WEBSOCKET
|
||||
implementation("org.springframework.boot:spring-boot-starter-websocket")
|
||||
|
||||
// SECURITY
|
||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
// implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
|
||||
// H2 Database
|
||||
runtimeOnly("com.h2database:h2")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,33 @@
|
|||
package fr.teamflash.fencerjudgeback.entities
|
||||
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.SequenceGenerator
|
||||
import jakarta.persistence.Table
|
||||
import java.util.Date
|
||||
import jakarta.validation.constraints.*
|
||||
|
||||
@Entity
|
||||
@Table(name="matchs")
|
||||
@Table(name="matches")
|
||||
data class MatchBean(
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "match_sequence")
|
||||
@SequenceGenerator(name = "match_sequence", sequenceName = "match_seq", allocationSize = 1)
|
||||
val id:Long?=null,
|
||||
val weapon:String?=null,
|
||||
val country:String?=null,
|
||||
val city:String?=null,
|
||||
@field:NotNull(message = "Player 1 ID must not be null")
|
||||
val player1ID:Long?=null,
|
||||
@field:NotNull(message = "Player 2 ID must not be null")
|
||||
val player2ID:Long?=null,
|
||||
val refereeID: Long?=null,
|
||||
@field:Min(value = 0, message = "Score must be at least 0")
|
||||
val score1:Int=0,
|
||||
@field:Min(value = 0, message = "Score must be at least 0")
|
||||
val score2:Int=0,
|
||||
val date: Date?=null
|
||||
val date: String?=null,
|
||||
val state:String?=null
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,13 +4,17 @@ import jakarta.persistence.Entity
|
|||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.SequenceGenerator
|
||||
import jakarta.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name="players")
|
||||
data class PlayerBean(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "player_sequence")
|
||||
@SequenceGenerator(name = "player_sequence", sequenceName = "player_seq", allocationSize = 1)
|
||||
val id:Long?=null,
|
||||
val name:String?="",
|
||||
val firstName:String?=""
|
||||
val firstName:String?="",
|
||||
val club:String?=""
|
||||
)
|
||||
|
|
@ -4,13 +4,17 @@ import jakarta.persistence.Entity
|
|||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.SequenceGenerator
|
||||
import jakarta.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name="referees")
|
||||
data class RefereeBean(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "referee_sequence")
|
||||
@SequenceGenerator(name = "referee_sequence", sequenceName = "referee_seq", allocationSize = 1)
|
||||
val id:Long?=null,
|
||||
val name:String?=null,
|
||||
val firstName:String?=null
|
||||
val firstName:String?=null,
|
||||
val qualification:String?=null
|
||||
)
|
||||
|
|
@ -2,10 +2,8 @@ package fr.teamflash.fencerjudgeback.restControllers
|
|||
|
||||
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
|
||||
@RequestMapping("/matches")
|
||||
|
|
@ -13,55 +11,74 @@ class MatchRestController(private val matchService: MatchService) {
|
|||
|
||||
// Lister tous les matchs
|
||||
@GetMapping("/")
|
||||
fun getAll(): ResponseEntity<List<MatchBean>> {
|
||||
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>?> {
|
||||
@GetMapping("/date/{date}")
|
||||
fun getAllFromDate(@PathVariable date:String): ResponseEntity<List<MatchBean?>?> {
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.date == date })
|
||||
}
|
||||
|
||||
// Lister tous les matchs par pays
|
||||
@GetMapping("/country/{country}")
|
||||
fun getAllFromCountry(@PathVariable country:String): ResponseEntity<List<MatchBean>?> {
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.country == country })
|
||||
}
|
||||
|
||||
// Lister tous les matchs par ville
|
||||
@GetMapping("/city/{city}")
|
||||
fun getAllFromCity(@PathVariable city:String): ResponseEntity<List<MatchBean>?> {
|
||||
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<List<MatchBean>?> {
|
||||
return ResponseEntity.ok(matchService.getByPlayers(player1ID, player2ID))
|
||||
}
|
||||
|
||||
// Lister les matchs en cours
|
||||
@GetMapping("/active")
|
||||
fun getAllActive(): ResponseEntity<List<MatchBean>?> {
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.state == ACTIVE })
|
||||
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 { })
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.state == "FINISHED" })
|
||||
}
|
||||
|
||||
// Lister les matchs non commencés
|
||||
@GetMapping("/not-started")
|
||||
fun getAllNotStarted(): ResponseEntity<List<MatchBean>?> {
|
||||
|
||||
return ResponseEntity.ok(matchService.getAll().filter { it.state == "NOT STARTED" })
|
||||
}
|
||||
|
||||
// Afficher un match par id
|
||||
@GetMapping("/{id}")
|
||||
fun getMatchById(@PathVariable id: Long): ResponseEntity<MatchBean?> {
|
||||
fun getById(@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))
|
||||
// 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 refereeID: Long, @RequestBody): ResponseEntity<MatchBean?> {
|
||||
return ResponseEntity.ok(matchService.updateMatch(match))
|
||||
fun updateMatch(@PathVariable id: Long, @RequestBody match: MatchBean): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(matchService.updateMatch(id, match))
|
||||
}
|
||||
|
||||
// Supprimer un match
|
||||
@DeleteMapping("/delete-match/{id}")
|
||||
fun deleteMatch(@PathVariable id: Long): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(matchService.deleteMatch(id))
|
||||
return ResponseEntity.ok(matchService.deleteMatchById(id))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,55 +5,62 @@ 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.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
|
||||
import java.util.Optional
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/players")
|
||||
class PlayerRestController(private val playerService: PlayerService) {
|
||||
|
||||
// Lister tous les joueurs
|
||||
@GetMapping
|
||||
@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?>?> {
|
||||
fun getById(@PathVariable id: Long): ResponseEntity<PlayerBean?> {
|
||||
return ResponseEntity.ok(playerService.getById(id))
|
||||
}
|
||||
|
||||
// Afficher un joueur par nom
|
||||
@GetMapping("/{name}")
|
||||
fun getByName(name: String): ResponseEntity<List<PlayerBean?>?> {
|
||||
// Afficher un ou plusieurs joueur(s) par nom
|
||||
@GetMapping("/name/{name}")
|
||||
fun getByName(@PathVariable 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?>?> {
|
||||
// Afficher un ou plusieurs joueur(s) par prénom
|
||||
@GetMapping("/firstName/{firstName}")
|
||||
fun getByFirstName(@PathVariable firstName: String): ResponseEntity<List<PlayerBean?>?> {
|
||||
return ResponseEntity.ok(playerService.getByFirstName(firstName))
|
||||
}
|
||||
|
||||
// Afficher un ou plusieurs joueur(s) par club
|
||||
@GetMapping("/club/{club}")
|
||||
fun getByClub(@PathVariable club: String): ResponseEntity<List<PlayerBean?>?> {
|
||||
return ResponseEntity.ok(playerService.getByClub(club))
|
||||
}
|
||||
|
||||
// Ajouter un joueur
|
||||
@PostMapping("/add-player")
|
||||
fun createPlayer(player: PlayerBean): ResponseEntity<PlayerBean> {
|
||||
@PostMapping("/create-player")
|
||||
fun createPlayer(@RequestBody 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))
|
||||
@PutMapping("/update-player/{id}")
|
||||
fun updatePlayer(@PathVariable id: Long, @RequestBody player: PlayerBean): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(playerService.updatePlayer(id, player))
|
||||
}
|
||||
|
||||
// Supprimer un joueur
|
||||
@DeleteMapping("/delete-player")
|
||||
fun deletePlayer(id: Long): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(playerService.deletePlayer(id))
|
||||
@DeleteMapping("/delete-player/{id}")
|
||||
fun deletePlayer(@PathVariable id: Long): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(playerService.deletePlayerById(id))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ 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
|
||||
import java.util.Optional
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/referees")
|
||||
|
|
@ -24,38 +24,44 @@ class RefereeRestController(private val refereeService: RefereeService) {
|
|||
|
||||
// Afficher un arbitre par id
|
||||
@GetMapping("/{id}")
|
||||
fun getById(id: Long): ResponseEntity<Optional<RefereeBean?>?> {
|
||||
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(name:String): ResponseEntity<List<RefereeBean?>?> {
|
||||
fun getByName(@PathVariable 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?>?> {
|
||||
// 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 qualification
|
||||
@GetMapping("/qualification/{qualification}")
|
||||
fun getByQualification(@PathVariable qualification:String): ResponseEntity<List<RefereeBean?>?> {
|
||||
return ResponseEntity.ok(refereeService.getByQualification(qualification))
|
||||
}
|
||||
|
||||
// Ajouter un arbitre
|
||||
@PostMapping("/create-referee")
|
||||
fun createReferee(referee: RefereeBean): ResponseEntity<RefereeBean> {
|
||||
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, name: String, firstName: String) : ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(refereeService.updateReferee(id, name, firstName))
|
||||
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(id:Long): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(refereeService.deleteReferee(id))
|
||||
fun deleteReferee(@PathVariable id:Long): ResponseEntity<Int> {
|
||||
return ResponseEntity.ok(refereeService.deleteRefereeById(id))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
package fr.teamflash.fencerjudgeback.services
|
||||
|
||||
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
||||
import fr.teamflash.fencerjudgeback.entities.PlayerBean
|
||||
import fr.teamflash.fencerjudgeback.repositories.MatchRepository
|
||||
import fr.teamflash.fencerjudgeback.websocket.controllers.MatchWebSocketController
|
||||
import fr.teamflash.fencerjudgeback.websocket.models.MatchUpdateMessage
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Lazy
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.Date
|
||||
|
||||
@Service
|
||||
class MatchService(
|
||||
|
|
@ -23,13 +19,19 @@ class MatchService(
|
|||
}
|
||||
|
||||
// Obtenir un match par id (public)
|
||||
fun getById(id:Long): MatchBean? {
|
||||
fun getById(id: Long?): MatchBean? {
|
||||
println("MatchService.getMatchById : $id")
|
||||
|
||||
if (id == null) {
|
||||
println("MatchService.getMatchById : Match not found")
|
||||
return null
|
||||
}
|
||||
|
||||
return matchRepository.findById(id).get()
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs match(s) par joueurs (id) (public)
|
||||
fun getByPlayers(player1ID: Long, player2ID: Long): List<MatchBean> {
|
||||
fun getByPlayers(player1ID: Long?, player2ID: Long?): List<MatchBean> {
|
||||
println("MatchService.getMatchByPlayers : $player1ID - $player2ID")
|
||||
return matchRepository.findAll().filter { it.player1ID == player1ID && it.player2ID == player2ID }
|
||||
}
|
||||
|
|
@ -44,61 +46,41 @@ class MatchService(
|
|||
}
|
||||
|
||||
// Modifier un match (admin)
|
||||
fun updateMatch(id: Long, date: Date, refereeID: Long, player1ID: Long, player2ID: Long, scorePlayer1:Int, scorePlayer2:Int) : Int {
|
||||
println("MatchService.updateMatch : $id - $refereeID - $player1ID - $player2ID - $scorePlayer1 - $scorePlayer2")
|
||||
fun updateMatch(id: Long?, newMatch: MatchBean): Int {
|
||||
println("MatchService.updateMatch : $newMatch")
|
||||
|
||||
if (getById(id) == null) {
|
||||
println("MatchService.updateMatch : Match not found")
|
||||
return -1
|
||||
}
|
||||
|
||||
// Broadcast the update via WebSocket
|
||||
// matchWebSocketController?.broadcastMatchUpdate(savedMatch, MatchUpdateMessage.UpdateType.SCORE_UPDATE)
|
||||
|
||||
// Créer nouveau MatchBean à l'id renseigné
|
||||
val newMatch = MatchBean(
|
||||
id = id,
|
||||
date = date,
|
||||
refereeID = refereeID,
|
||||
player1ID = player1ID,
|
||||
player2ID = player2ID,
|
||||
score1 = scorePlayer1,
|
||||
score2 = scorePlayer2
|
||||
)
|
||||
|
||||
// if (
|
||||
// // Supprimer le MatchBean à l'id en paramètre
|
||||
// deleteMatch(id) == 1
|
||||
// && createMatch(newMatch) == 1) {
|
||||
//
|
||||
// // Insérer le nouveau MatchBean à l'id en paramètre
|
||||
//
|
||||
//
|
||||
// return 1
|
||||
// }
|
||||
|
||||
// Supprimer le MatchBean à l'id en paramètre
|
||||
if (deleteMatch(id) == 1) {
|
||||
// Insérer le nouveau MatchBean à l'id en paramètre
|
||||
createMatch(newMatch)
|
||||
}
|
||||
|
||||
val updatedMatch = newMatch.copy(id = id)
|
||||
matchRepository.save(updatedMatch)
|
||||
return 1
|
||||
}
|
||||
|
||||
// Supprimer un match (admin)
|
||||
fun deleteMatch(id:Long) : Int {
|
||||
println("MatchService.deleteMatch : $id")
|
||||
fun deleteMatchById(id: Long?) : Int? {
|
||||
println("MatchService.deleteMatchById : $id")
|
||||
|
||||
try {
|
||||
matchRepository.deleteById(id)
|
||||
} catch (e: Exception) {
|
||||
println("Error deleting match: ${e.message}")
|
||||
if (getById(id) == null) {
|
||||
println("MatchService.deleteMatchById : Match not found")
|
||||
return -1
|
||||
}
|
||||
|
||||
// Broadcast the match cancellation via WebSocket before deleting
|
||||
// matchWebSocketController?.broadcastMatchUpdate(matchID, MatchUpdateMessage.UpdateType.MATCH_CANCEL)
|
||||
matchRepository.deleteById(id!!)
|
||||
return 1
|
||||
}
|
||||
|
||||
fun getMatchesByCity(city: String): List<MatchBean>? {
|
||||
println("MatchService.getMatchesByCity : $city")
|
||||
|
||||
return matchRepository.findAll()
|
||||
.filter { it.city == city }
|
||||
}
|
||||
|
||||
fun getMatchesByCountry(country: String): List<MatchBean>? {
|
||||
println("MatchService.getMatchesByCountry : $country")
|
||||
|
||||
return matchRepository.findAll()
|
||||
.filter { it.country == country }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,70 +4,74 @@ import fr.teamflash.fencerjudgeback.entities.PlayerBean
|
|||
import fr.teamflash.fencerjudgeback.repositories.PlayerRepository
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.Optional
|
||||
|
||||
@Service
|
||||
class PlayerService(@Autowired private val playerRepository: PlayerRepository) {
|
||||
// Obtenir tous les joueurs (public)
|
||||
fun getAll(): List<PlayerBean> {
|
||||
println("RefereeService.getReferees")
|
||||
println("PlayerService.getAll")
|
||||
return playerRepository.findAll()
|
||||
}
|
||||
|
||||
// Obtenir un joueur par id (public)
|
||||
fun getById(id:Long) : Optional<PlayerBean?> {
|
||||
println("RefereeService.getRefereeById : $id")
|
||||
return playerRepository.findById(id)
|
||||
fun getById(id:Long?) : PlayerBean? {
|
||||
println("PlayerService.getById : $id")
|
||||
|
||||
if (id == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return playerRepository.findById(id).get()
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs joueur(s) par nom (public)
|
||||
fun getByName(name:String): List<PlayerBean?>? {
|
||||
println("RefereeService.getRefereeByName : $name")
|
||||
println("PlayerService.getByName : $name")
|
||||
return playerRepository.findAll().filter{ it.name == name }
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs joueur(s) par prénom
|
||||
fun getByFirstName(firstName:String): List<PlayerBean?>? {
|
||||
println("RefereeService.getRefereeByFirstName : $firstName")
|
||||
println("PlayerService.getByFirstName : $firstName")
|
||||
return playerRepository.findAll().filter{ it.firstName == firstName }
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs joueur(s) par club
|
||||
fun getByClub(club:String): List<PlayerBean?>? {
|
||||
println("PlayerService.getByClub : $club")
|
||||
return playerRepository.findAll().filter{ it.club == club }
|
||||
}
|
||||
|
||||
// Ajouter un joueur (admin)
|
||||
fun createPlayer(referee: PlayerBean) : PlayerBean {
|
||||
println("RefereeService.createReferee : $referee")
|
||||
println("PlayerService.createPlayer : $referee")
|
||||
return playerRepository.save(referee)
|
||||
}
|
||||
|
||||
// Modifier un joueur (admin)
|
||||
fun updatePlayer(id:Long, name:String, firstName: String) : Int {
|
||||
fun updatePlayer(id:Long, newPlayer: PlayerBean) : Int {
|
||||
// Vérifier si le joueur existe à l'id renseigné
|
||||
if (getById(id) == null) {
|
||||
println("RefereeService.updateReferee : Referee not found")
|
||||
println("PlayerService.updatePlayer : Player not found")
|
||||
return -1
|
||||
}
|
||||
|
||||
// Créer nouveau PlayerBean à l'id renseigné
|
||||
val newPlayer = PlayerBean(id, name, firstName)
|
||||
|
||||
// Supprimer le PlayerBean à l'id en paramètre
|
||||
deletePlayer(id)
|
||||
|
||||
// Insérer le nouveau PlayerBean
|
||||
createPlayer(newPlayer)
|
||||
val updatedPlayer = newPlayer.copy(id = id)
|
||||
playerRepository.save(updatedPlayer)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
// Supprimer un joueur (admin)
|
||||
fun deletePlayer(id:Long): Int {
|
||||
println("RefereeService.deleteReferee : $id")
|
||||
fun deletePlayerById(id:Long?): Int {
|
||||
println("PlayerService.deletePlayer : $id")
|
||||
|
||||
if (getById(id) == null) {
|
||||
println("RefereeService.deleteReferee : Referee not found")
|
||||
println("PlayerService.deletePlayer : Player not found")
|
||||
return -1
|
||||
}
|
||||
|
||||
playerRepository.deleteById(id)
|
||||
playerRepository.deleteById(id!!)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,7 @@ package fr.teamflash.fencerjudgeback.services
|
|||
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
||||
import fr.teamflash.fencerjudgeback.repositories.RefereeRepository
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable_.id
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.Optional
|
||||
|
||||
@Service
|
||||
class RefereeService(@Autowired private val refereeRepository: RefereeRepository) {
|
||||
|
|
@ -16,9 +14,14 @@ class RefereeService(@Autowired private val refereeRepository: RefereeRepository
|
|||
}
|
||||
|
||||
// Obtenir un arbitre par id (public)
|
||||
fun getById(id:Long) : Optional<RefereeBean?> {
|
||||
fun getById(id:Long?) : RefereeBean? {
|
||||
println("RefereeService.getRefereeById : $id")
|
||||
return refereeRepository.findById(id)
|
||||
|
||||
if (id == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return refereeRepository.findById(id).get()
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs arbitre(s) par nom (public)
|
||||
|
|
@ -33,6 +36,12 @@ class RefereeService(@Autowired private val refereeRepository: RefereeRepository
|
|||
return refereeRepository.findAll().filter{ it.firstName == firstName }
|
||||
}
|
||||
|
||||
// Obtenir un ou plusieurs arbitre(s) par qualification
|
||||
fun getByQualification(qualification:String): List<RefereeBean?>? {
|
||||
println("RefereeService.getRefereeByQualification : $qualification")
|
||||
return refereeRepository.findAll().filter{ it.qualification == qualification }
|
||||
}
|
||||
|
||||
// Ajouter un arbitre (admin)
|
||||
fun createReferee(referee: RefereeBean) : RefereeBean {
|
||||
println("RefereeService.createReferee : $referee")
|
||||
|
|
@ -40,27 +49,19 @@ class RefereeService(@Autowired private val refereeRepository: RefereeRepository
|
|||
}
|
||||
|
||||
// Modifier un arbitre (admin)
|
||||
fun updateReferee(id:Long, name:String, firstName: String) : Int {
|
||||
fun updateReferee(id:Long, newReferee: RefereeBean) : Int? {
|
||||
// Vérifier si l'arbitre existe à l'id renseigné
|
||||
if (getById(id) == null) {
|
||||
println("RefereeService.updateReferee : Referee not found")
|
||||
return -1
|
||||
}
|
||||
|
||||
// Créer nouveau RefereeBean à l'id renseigné
|
||||
val newReferee = RefereeBean(id, name, firstName)
|
||||
|
||||
// Supprimer le RefereeBean à l'id en paramètre
|
||||
deleteReferee(id)
|
||||
|
||||
// Insérer le nouveau RefereeBean à l'id en paramètre
|
||||
createReferee(newReferee)
|
||||
|
||||
val updatedMatch = newReferee.copy(id = id)
|
||||
refereeRepository.save(updatedMatch)
|
||||
return 1
|
||||
}
|
||||
|
||||
// Supprimer un arbitre (admin)
|
||||
fun deleteReferee(id:Long): Int {
|
||||
fun deleteRefereeById(id:Long): Int {
|
||||
println("RefereeService.deleteReferee : $id")
|
||||
|
||||
if (getById(id) == null) {
|
||||
|
|
|
|||
|
|
@ -1 +1,16 @@
|
|||
spring.application.name=FencerJudgeBack
|
||||
|
||||
# H2 Database Configuration
|
||||
spring.datasource.url=jdbc:h2:file:./db;AUTO_SERVER=true
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
# Enable H2 Console
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.path=/h2-console
|
||||
|
||||
# Hibernate Configuration
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
138
FencerJudgeBack/test.http
Normal file
138
FencerJudgeBack/test.http
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
### Get all matches
|
||||
GET http://localhost:8080/matches/
|
||||
|
||||
### Get matches by players --> TODO
|
||||
GET http://localhost:8080/matches/players/1/2
|
||||
|
||||
### Get matches by date
|
||||
GET http://localhost:8080/matches/date/2025-06-02
|
||||
|
||||
### Get matches by country
|
||||
GET http://localhost:8080/matches/country/France
|
||||
|
||||
### Get matches by city
|
||||
GET http://localhost:8080/matches/city/Paris
|
||||
|
||||
### Get active matches
|
||||
GET http://localhost:8080/matches/active
|
||||
|
||||
### Get finished matches
|
||||
GET http://localhost:8080/matches/over
|
||||
|
||||
### Get not started matches
|
||||
GET http://localhost:8080/matches/not-started
|
||||
|
||||
### Get match by ID
|
||||
GET http://localhost:8080/matches/2
|
||||
|
||||
### Create new match
|
||||
POST http://localhost:8080/matches/create-match
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"weapon": "Épée",
|
||||
"country": "France",
|
||||
"city": "Paris",
|
||||
"player1ID": 1,
|
||||
"player2ID": 2,
|
||||
"refereeID": 1,
|
||||
"score1": 0,
|
||||
"score2": 0,
|
||||
"date": "2025-06-02",
|
||||
"state": "NOT STARTED"
|
||||
}
|
||||
|
||||
### Update match
|
||||
PUT http://localhost:8080/matches/update-match/4
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
"weapon": "Épée",
|
||||
"country": "France",
|
||||
"city": "Paris",
|
||||
"player1ID": 1,
|
||||
"player2ID": 2,
|
||||
"refereeID": 1,
|
||||
"score1": 5,
|
||||
"score2": 3,
|
||||
"date": "2025-06-02",
|
||||
"state": "OVER"
|
||||
}
|
||||
|
||||
### Delete match
|
||||
DELETE http://localhost:8080/matches/delete-match/3
|
||||
|
||||
### Get all referees
|
||||
GET http://localhost:8080/referees/
|
||||
|
||||
### Get referee by ID
|
||||
GET http://localhost:8080/referees/1
|
||||
|
||||
### Get referees by name
|
||||
GET http://localhost:8080/referees/name/Smith
|
||||
|
||||
### Get referees by firstname
|
||||
GET http://localhost:8080/referees/firstname/John
|
||||
|
||||
### Get referees by qualification
|
||||
GET http://localhost:8080/referees/qualification/NATIONAL
|
||||
|
||||
### Create new referee
|
||||
POST http://localhost:8080/referees/create-referee
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "Smith",
|
||||
"firstName": "John",
|
||||
"qualification": "NATIONAL"
|
||||
}
|
||||
|
||||
### Update referee
|
||||
PUT http://localhost:8080/referees/update-referee/6
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "Smith",
|
||||
"firstName": "John",
|
||||
"qualification": "INTERNATIONAL"
|
||||
}
|
||||
|
||||
### Delete referee
|
||||
DELETE http://localhost:8080/referees/delete-referee/5
|
||||
|
||||
### Get all players
|
||||
GET http://localhost:8080/players/
|
||||
|
||||
### Get player by ID
|
||||
GET http://localhost:8080/players/10
|
||||
|
||||
### Get players by name
|
||||
GET http://localhost:8080/players/name/Doe
|
||||
|
||||
### Get players by firstname
|
||||
GET http://localhost:8080/players/firstname/Jane
|
||||
|
||||
### Create new player
|
||||
POST http://localhost:8080/players/create-player
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "Doe",
|
||||
"firstName": "Jane",
|
||||
"club": "Paris Escrime Club"
|
||||
}
|
||||
|
||||
### Update player
|
||||
PUT http://localhost:8080/players/update-player/10
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "Doe",
|
||||
"firstName": "Jane",
|
||||
"club": "Un autre club"
|
||||
}
|
||||
|
||||
### Delete player
|
||||
DELETE http://localhost:8080/players/delete-player/10
|
||||
|
||||
Loading…
Add table
Reference in a new issue