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
|
|
@ -1,4 +1,6 @@
|
||||||
corriger les services - ~
|
corriger les services - ~
|
||||||
tester les restcontrollers via des requêtes http - ~
|
tester les restcontrollers via des requêtes http - ~
|
||||||
créer la bdd avec toutes les tables (repositories)
|
créer la bdd avec toutes les tables (repositories)
|
||||||
tester le websocket
|
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.springframework.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||||
|
|
||||||
// WEBSOCKET
|
// WEBSOCKET
|
||||||
implementation("org.springframework.boot:spring-boot-starter-websocket")
|
implementation("org.springframework.boot:spring-boot-starter-websocket")
|
||||||
|
|
||||||
// SECURITY
|
// SECURITY
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
// implementation("org.springframework.boot:spring-boot-starter-security")
|
||||||
|
|
||||||
|
// H2 Database
|
||||||
|
runtimeOnly("com.h2database:h2")
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,33 @@
|
||||||
package fr.teamflash.fencerjudgeback.entities
|
package fr.teamflash.fencerjudgeback.entities
|
||||||
|
|
||||||
import jakarta.persistence.Entity
|
import jakarta.persistence.Entity
|
||||||
|
import jakarta.persistence.GeneratedValue
|
||||||
|
import jakarta.persistence.GenerationType
|
||||||
import jakarta.persistence.Id
|
import jakarta.persistence.Id
|
||||||
|
import jakarta.persistence.SequenceGenerator
|
||||||
import jakarta.persistence.Table
|
import jakarta.persistence.Table
|
||||||
import java.util.Date
|
import jakarta.validation.constraints.*
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="matchs")
|
@Table(name="matches")
|
||||||
data class MatchBean(
|
data class MatchBean(
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "match_sequence")
|
||||||
|
@SequenceGenerator(name = "match_sequence", sequenceName = "match_seq", allocationSize = 1)
|
||||||
val id:Long?=null,
|
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,
|
val player1ID:Long?=null,
|
||||||
|
@field:NotNull(message = "Player 2 ID must not be null")
|
||||||
val player2ID:Long?=null,
|
val player2ID:Long?=null,
|
||||||
val refereeID: Long?=null,
|
val refereeID: Long?=null,
|
||||||
|
@field:Min(value = 0, message = "Score must be at least 0")
|
||||||
val score1:Int=0,
|
val score1:Int=0,
|
||||||
|
@field:Min(value = 0, message = "Score must be at least 0")
|
||||||
val score2:Int=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.GeneratedValue
|
||||||
import jakarta.persistence.GenerationType
|
import jakarta.persistence.GenerationType
|
||||||
import jakarta.persistence.Id
|
import jakarta.persistence.Id
|
||||||
|
import jakarta.persistence.SequenceGenerator
|
||||||
import jakarta.persistence.Table
|
import jakarta.persistence.Table
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="players")
|
@Table(name="players")
|
||||||
data class PlayerBean(
|
data class PlayerBean(
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "player_sequence")
|
||||||
|
@SequenceGenerator(name = "player_sequence", sequenceName = "player_seq", allocationSize = 1)
|
||||||
val id:Long?=null,
|
val id:Long?=null,
|
||||||
val name:String?="",
|
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.GeneratedValue
|
||||||
import jakarta.persistence.GenerationType
|
import jakarta.persistence.GenerationType
|
||||||
import jakarta.persistence.Id
|
import jakarta.persistence.Id
|
||||||
|
import jakarta.persistence.SequenceGenerator
|
||||||
import jakarta.persistence.Table
|
import jakarta.persistence.Table
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="referees")
|
@Table(name="referees")
|
||||||
data class RefereeBean(
|
data class RefereeBean(
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "referee_sequence")
|
||||||
|
@SequenceGenerator(name = "referee_sequence", sequenceName = "referee_seq", allocationSize = 1)
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
@ -2,10 +2,8 @@ package fr.teamflash.fencerjudgeback.restControllers
|
||||||
|
|
||||||
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
||||||
import fr.teamflash.fencerjudgeback.services.MatchService
|
import fr.teamflash.fencerjudgeback.services.MatchService
|
||||||
import org.springframework.http.HttpStatus
|
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/matches")
|
@RequestMapping("/matches")
|
||||||
|
|
@ -13,55 +11,74 @@ class MatchRestController(private val matchService: MatchService) {
|
||||||
|
|
||||||
// Lister tous les matchs
|
// Lister tous les matchs
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
fun getAll(): ResponseEntity<List<MatchBean>> {
|
fun getAll(): ResponseEntity<List<MatchBean>?> {
|
||||||
return ResponseEntity.ok(matchService.getAll())
|
return ResponseEntity.ok(matchService.getAll())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lister tous les matchs à partir d'une certaine date
|
// Lister tous les matchs à partir d'une certaine date
|
||||||
@GetMapping("/{date}")
|
@GetMapping("/date/{date}")
|
||||||
fun getAllFromDate(date:Date): ResponseEntity<List<MatchBean>?> {
|
fun getAllFromDate(@PathVariable date:String): ResponseEntity<List<MatchBean?>?> {
|
||||||
return ResponseEntity.ok(matchService.getAll().filter { it.date == date })
|
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
|
// 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 == "ACTIVE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 { })
|
return ResponseEntity.ok(matchService.getAll().filter { it.state == "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" })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un match par id
|
// Afficher un match par id
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
fun getMatchById(@PathVariable id: Long): ResponseEntity<MatchBean?> {
|
fun getById(@PathVariable id: Long): ResponseEntity<MatchBean?> {
|
||||||
return ResponseEntity.ok(matchService.getById(id))
|
return ResponseEntity.ok(matchService.getById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter un match
|
// Ajouter un match
|
||||||
@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.status(HttpStatus.CREATED).body(matchService.createMatch(match))
|
||||||
|
return ResponseEntity.ok(matchService.createMatch(match))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mettre à jour un match
|
// Mettre à jour un match
|
||||||
@PutMapping("/update-match/{id}")
|
@PutMapping("/update-match/{id}")
|
||||||
fun updateMatch(@PathVariable id: Long, @RequestBody refereeID: Long, @RequestBody): ResponseEntity<MatchBean?> {
|
fun updateMatch(@PathVariable id: Long, @RequestBody match: MatchBean): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(matchService.updateMatch(match))
|
return ResponseEntity.ok(matchService.updateMatch(id, match))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un match
|
// Supprimer un match
|
||||||
@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.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.http.ResponseEntity
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping
|
import org.springframework.web.bind.annotation.DeleteMapping
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
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.PostMapping
|
||||||
import org.springframework.web.bind.annotation.PutMapping
|
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.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.util.Optional
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/players")
|
@RequestMapping("/players")
|
||||||
class PlayerRestController(private val playerService: PlayerService) {
|
class PlayerRestController(private val playerService: PlayerService) {
|
||||||
|
|
||||||
// Lister tous les joueurs
|
// Lister tous les joueurs
|
||||||
@GetMapping
|
@GetMapping("/")
|
||||||
fun getAll(): ResponseEntity<List<PlayerBean>> {
|
fun getAll(): ResponseEntity<List<PlayerBean>> {
|
||||||
return ResponseEntity.ok(playerService.getAll())
|
return ResponseEntity.ok(playerService.getAll())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un joueur par id
|
// Afficher un joueur par id
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
fun getById(id: Long): ResponseEntity<Optional<PlayerBean?>?> {
|
fun getById(@PathVariable id: Long): ResponseEntity<PlayerBean?> {
|
||||||
return ResponseEntity.ok(playerService.getById(id))
|
return ResponseEntity.ok(playerService.getById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un joueur par nom
|
// Afficher un ou plusieurs joueur(s) par nom
|
||||||
@GetMapping("/{name}")
|
@GetMapping("/name/{name}")
|
||||||
fun getByName(name: String): ResponseEntity<List<PlayerBean?>?> {
|
fun getByName(@PathVariable name: String): ResponseEntity<List<PlayerBean?>?> {
|
||||||
return ResponseEntity.ok(playerService.getByName(name))
|
return ResponseEntity.ok(playerService.getByName(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un joueur par prénom
|
// Afficher un ou plusieurs joueur(s) par prénom
|
||||||
@GetMapping("/{firstName}")
|
@GetMapping("/firstName/{firstName}")
|
||||||
fun getByFirstName(firstName: String): ResponseEntity<List<PlayerBean?>?> {
|
fun getByFirstName(@PathVariable firstName: String): ResponseEntity<List<PlayerBean?>?> {
|
||||||
return ResponseEntity.ok(playerService.getByFirstName(firstName))
|
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
|
// Ajouter un joueur
|
||||||
@PostMapping("/add-player")
|
@PostMapping("/create-player")
|
||||||
fun createPlayer(player: PlayerBean): ResponseEntity<PlayerBean> {
|
fun createPlayer(@RequestBody player: PlayerBean): ResponseEntity<PlayerBean> {
|
||||||
return ResponseEntity.ok(playerService.createPlayer(player))
|
return ResponseEntity.ok(playerService.createPlayer(player))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier un joueur
|
// Modifier un joueur
|
||||||
@PutMapping("/update-player")
|
@PutMapping("/update-player/{id}")
|
||||||
fun updatePlayer(id: Long, name: String, firstName: String): ResponseEntity<Int> {
|
fun updatePlayer(@PathVariable id: Long, @RequestBody player: PlayerBean): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(playerService.updatePlayer(id, name, firstName))
|
return ResponseEntity.ok(playerService.updatePlayer(id, player))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un joueur
|
// Supprimer un joueur
|
||||||
@DeleteMapping("/delete-player")
|
@DeleteMapping("/delete-player/{id}")
|
||||||
fun deletePlayer(id: Long): ResponseEntity<Int> {
|
fun deletePlayer(@PathVariable id: Long): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(playerService.deletePlayer(id))
|
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.PathVariable
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
import org.springframework.web.bind.annotation.PutMapping
|
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.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.util.Optional
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/referees")
|
@RequestMapping("/referees")
|
||||||
|
|
@ -24,38 +24,44 @@ class RefereeRestController(private val refereeService: RefereeService) {
|
||||||
|
|
||||||
// Afficher un arbitre par id
|
// Afficher un arbitre par id
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
fun getById(id: Long): ResponseEntity<Optional<RefereeBean?>?> {
|
fun getById(@PathVariable id: Long): ResponseEntity<RefereeBean?> {
|
||||||
return ResponseEntity.ok(refereeService.getById(id))
|
return ResponseEntity.ok(refereeService.getById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher un ou plusieurs arbitre(s) par nom
|
// Afficher un ou plusieurs arbitre(s) par nom
|
||||||
@GetMapping("/name/{name}")
|
@GetMapping("/name/{name}")
|
||||||
fun getByName(name:String): ResponseEntity<List<RefereeBean?>?> {
|
fun getByName(@PathVariable name:String): ResponseEntity<List<RefereeBean?>?> {
|
||||||
return ResponseEntity.ok(refereeService.getByName(name))
|
return ResponseEntity.ok(refereeService.getByName(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Afficher ou plusieurs arbitre(s) par prénom
|
// Afficher un ou plusieurs arbitre(s) par prénom
|
||||||
@GetMapping("/first-name/{firstName}")
|
@GetMapping("/firstname/{firstName}")
|
||||||
fun getByFirstName(firstName:String): ResponseEntity<List<RefereeBean?>?> {
|
fun getByFirstName(@PathVariable firstName:String): ResponseEntity<List<RefereeBean?>?> {
|
||||||
return ResponseEntity.ok(refereeService.getByFirstName(firstName))
|
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
|
// Ajouter un arbitre
|
||||||
@PostMapping("/create-referee")
|
@PostMapping("/create-referee")
|
||||||
fun createReferee(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
|
||||||
@PutMapping("/update-referee/{id}")
|
@PutMapping("/update-referee/{id}")
|
||||||
fun updateReferee(@PathVariable id: Long, name: String, firstName: String) : ResponseEntity<Int> {
|
fun updateReferee(@PathVariable id: Long, @RequestBody referee: RefereeBean) : ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(refereeService.updateReferee(id, name, firstName))
|
return ResponseEntity.ok(refereeService.updateReferee(id, referee))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un arbitre
|
// Supprimer un arbitre
|
||||||
@DeleteMapping("/delete-referee/{id}")
|
@DeleteMapping("/delete-referee/{id}")
|
||||||
fun deleteReferee(id:Long): ResponseEntity<Int> {
|
fun deleteReferee(@PathVariable id:Long): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(refereeService.deleteReferee(id))
|
return ResponseEntity.ok(refereeService.deleteRefereeById(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
package fr.teamflash.fencerjudgeback.services
|
package fr.teamflash.fencerjudgeback.services
|
||||||
|
|
||||||
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
import fr.teamflash.fencerjudgeback.entities.MatchBean
|
||||||
import fr.teamflash.fencerjudgeback.entities.PlayerBean
|
|
||||||
import fr.teamflash.fencerjudgeback.repositories.MatchRepository
|
import fr.teamflash.fencerjudgeback.repositories.MatchRepository
|
||||||
import fr.teamflash.fencerjudgeback.websocket.controllers.MatchWebSocketController
|
import fr.teamflash.fencerjudgeback.websocket.controllers.MatchWebSocketController
|
||||||
import fr.teamflash.fencerjudgeback.websocket.models.MatchUpdateMessage
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.context.annotation.Lazy
|
import org.springframework.context.annotation.Lazy
|
||||||
import org.springframework.http.ResponseEntity
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class MatchService(
|
class MatchService(
|
||||||
|
|
@ -23,13 +19,19 @@ class MatchService(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un match par id (public)
|
// Obtenir un match par id (public)
|
||||||
fun getById(id:Long): MatchBean? {
|
fun getById(id: Long?): MatchBean? {
|
||||||
println("MatchService.getMatchById : $id")
|
println("MatchService.getMatchById : $id")
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
println("MatchService.getMatchById : Match not found")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return matchRepository.findById(id).get()
|
return matchRepository.findById(id).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un ou plusieurs match(s) par joueurs (id) (public)
|
// 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")
|
println("MatchService.getMatchByPlayers : $player1ID - $player2ID")
|
||||||
return matchRepository.findAll().filter { it.player1ID == player1ID && it.player2ID == player2ID }
|
return matchRepository.findAll().filter { it.player1ID == player1ID && it.player2ID == player2ID }
|
||||||
}
|
}
|
||||||
|
|
@ -44,61 +46,41 @@ class MatchService(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier un match (admin)
|
// Modifier un match (admin)
|
||||||
fun updateMatch(id: Long, date: Date, refereeID: Long, player1ID: Long, player2ID: Long, scorePlayer1:Int, scorePlayer2:Int) : Int {
|
fun updateMatch(id: Long?, newMatch: MatchBean): Int {
|
||||||
println("MatchService.updateMatch : $id - $refereeID - $player1ID - $player2ID - $scorePlayer1 - $scorePlayer2")
|
println("MatchService.updateMatch : $newMatch")
|
||||||
|
|
||||||
if (getById(id) == null) {
|
if (getById(id) == null) {
|
||||||
println("MatchService.updateMatch : Match not found")
|
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast the update via WebSocket
|
val updatedMatch = newMatch.copy(id = id)
|
||||||
// matchWebSocketController?.broadcastMatchUpdate(savedMatch, MatchUpdateMessage.UpdateType.SCORE_UPDATE)
|
matchRepository.save(updatedMatch)
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un match (admin)
|
// Supprimer un match (admin)
|
||||||
fun deleteMatch(id:Long) : Int {
|
fun deleteMatchById(id: Long?) : Int? {
|
||||||
println("MatchService.deleteMatch : $id")
|
println("MatchService.deleteMatchById : $id")
|
||||||
|
|
||||||
try {
|
if (getById(id) == null) {
|
||||||
matchRepository.deleteById(id)
|
println("MatchService.deleteMatchById : Match not found")
|
||||||
} catch (e: Exception) {
|
|
||||||
println("Error deleting match: ${e.message}")
|
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
matchRepository.deleteById(id!!)
|
||||||
// Broadcast the match cancellation via WebSocket before deleting
|
|
||||||
// matchWebSocketController?.broadcastMatchUpdate(matchID, MatchUpdateMessage.UpdateType.MATCH_CANCEL)
|
|
||||||
return 1
|
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 fr.teamflash.fencerjudgeback.repositories.PlayerRepository
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.Optional
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class PlayerService(@Autowired private val playerRepository: PlayerRepository) {
|
class PlayerService(@Autowired private val playerRepository: PlayerRepository) {
|
||||||
// Obtenir tous les joueurs (public)
|
// Obtenir tous les joueurs (public)
|
||||||
fun getAll(): List<PlayerBean> {
|
fun getAll(): List<PlayerBean> {
|
||||||
println("RefereeService.getReferees")
|
println("PlayerService.getAll")
|
||||||
return playerRepository.findAll()
|
return playerRepository.findAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un joueur par id (public)
|
// Obtenir un joueur par id (public)
|
||||||
fun getById(id:Long) : Optional<PlayerBean?> {
|
fun getById(id:Long?) : PlayerBean? {
|
||||||
println("RefereeService.getRefereeById : $id")
|
println("PlayerService.getById : $id")
|
||||||
return playerRepository.findById(id)
|
|
||||||
|
if (id == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerRepository.findById(id).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un ou plusieurs joueur(s) par nom (public)
|
// Obtenir un ou plusieurs joueur(s) par nom (public)
|
||||||
fun getByName(name:String): List<PlayerBean?>? {
|
fun getByName(name:String): List<PlayerBean?>? {
|
||||||
println("RefereeService.getRefereeByName : $name")
|
println("PlayerService.getByName : $name")
|
||||||
return playerRepository.findAll().filter{ it.name == name }
|
return playerRepository.findAll().filter{ it.name == name }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un ou plusieurs joueur(s) par prénom
|
// Obtenir un ou plusieurs joueur(s) par prénom
|
||||||
fun getByFirstName(firstName:String): List<PlayerBean?>? {
|
fun getByFirstName(firstName:String): List<PlayerBean?>? {
|
||||||
println("RefereeService.getRefereeByFirstName : $firstName")
|
println("PlayerService.getByFirstName : $firstName")
|
||||||
return playerRepository.findAll().filter{ it.firstName == 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)
|
// Ajouter un joueur (admin)
|
||||||
fun createPlayer(referee: PlayerBean) : PlayerBean {
|
fun createPlayer(referee: PlayerBean) : PlayerBean {
|
||||||
println("RefereeService.createReferee : $referee")
|
println("PlayerService.createPlayer : $referee")
|
||||||
return playerRepository.save(referee)
|
return playerRepository.save(referee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier un joueur (admin)
|
// 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é
|
// Vérifier si le joueur existe à l'id renseigné
|
||||||
if (getById(id) == null) {
|
if (getById(id) == null) {
|
||||||
println("RefereeService.updateReferee : Referee not found")
|
println("PlayerService.updatePlayer : Player not found")
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Créer nouveau PlayerBean à l'id renseigné
|
val updatedPlayer = newPlayer.copy(id = id)
|
||||||
val newPlayer = PlayerBean(id, name, firstName)
|
playerRepository.save(updatedPlayer)
|
||||||
|
|
||||||
// Supprimer le PlayerBean à l'id en paramètre
|
|
||||||
deletePlayer(id)
|
|
||||||
|
|
||||||
// Insérer le nouveau PlayerBean
|
|
||||||
createPlayer(newPlayer)
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un joueur (admin)
|
// Supprimer un joueur (admin)
|
||||||
fun deletePlayer(id:Long): Int {
|
fun deletePlayerById(id:Long?): Int {
|
||||||
println("RefereeService.deleteReferee : $id")
|
println("PlayerService.deletePlayer : $id")
|
||||||
|
|
||||||
if (getById(id) == null) {
|
if (getById(id) == null) {
|
||||||
println("RefereeService.deleteReferee : Referee not found")
|
println("PlayerService.deletePlayer : Player not found")
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
playerRepository.deleteById(id)
|
playerRepository.deleteById(id!!)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,9 +3,7 @@ package fr.teamflash.fencerjudgeback.services
|
||||||
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
||||||
import fr.teamflash.fencerjudgeback.repositories.RefereeRepository
|
import fr.teamflash.fencerjudgeback.repositories.RefereeRepository
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.data.jpa.domain.AbstractPersistable_.id
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.Optional
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class RefereeService(@Autowired private val refereeRepository: RefereeRepository) {
|
class RefereeService(@Autowired private val refereeRepository: RefereeRepository) {
|
||||||
|
|
@ -16,9 +14,14 @@ class RefereeService(@Autowired private val refereeRepository: RefereeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtenir un arbitre par id (public)
|
// Obtenir un arbitre par id (public)
|
||||||
fun getById(id:Long) : Optional<RefereeBean?> {
|
fun getById(id:Long?) : RefereeBean? {
|
||||||
println("RefereeService.getRefereeById : $id")
|
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)
|
// 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 }
|
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)
|
// Ajouter un arbitre (admin)
|
||||||
fun createReferee(referee: RefereeBean) : RefereeBean {
|
fun createReferee(referee: RefereeBean) : RefereeBean {
|
||||||
println("RefereeService.createReferee : $referee")
|
println("RefereeService.createReferee : $referee")
|
||||||
|
|
@ -40,27 +49,19 @@ class RefereeService(@Autowired private val refereeRepository: RefereeRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier un arbitre (admin)
|
// 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é
|
// Vérifier si l'arbitre existe à l'id renseigné
|
||||||
if (getById(id) == null) {
|
if (getById(id) == null) {
|
||||||
println("RefereeService.updateReferee : Referee not found")
|
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Créer nouveau RefereeBean à l'id renseigné
|
val updatedMatch = newReferee.copy(id = id)
|
||||||
val newReferee = RefereeBean(id, name, firstName)
|
refereeRepository.save(updatedMatch)
|
||||||
|
|
||||||
// Supprimer le RefereeBean à l'id en paramètre
|
|
||||||
deleteReferee(id)
|
|
||||||
|
|
||||||
// Insérer le nouveau RefereeBean à l'id en paramètre
|
|
||||||
createReferee(newReferee)
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un arbitre (admin)
|
// Supprimer un arbitre (admin)
|
||||||
fun deleteReferee(id:Long): Int {
|
fun deleteRefereeById(id:Long): Int {
|
||||||
println("RefereeService.deleteReferee : $id")
|
println("RefereeService.deleteReferee : $id")
|
||||||
|
|
||||||
if (getById(id) == null) {
|
if (getById(id) == null) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1,16 @@
|
||||||
spring.application.name=FencerJudgeBack
|
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