ajout cors aux restcontrollers
This commit is contained in:
parent
81893b0dfe
commit
6c1e7491d6
3 changed files with 25 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
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.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.*
|
||||||
|
|
@ -9,6 +10,10 @@ import org.springframework.web.bind.annotation.*
|
||||||
@RequestMapping("/matches")
|
@RequestMapping("/matches")
|
||||||
class MatchRestController(private val matchService: MatchService) {
|
class MatchRestController(private val matchService: MatchService) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val URL_ORIGIN: String = "http://localhost:8080"
|
||||||
|
}
|
||||||
|
|
||||||
// Lister tous les matchs
|
// Lister tous les matchs
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
fun getAll(): ResponseEntity<List<MatchBean>?> {
|
fun getAll(): ResponseEntity<List<MatchBean>?> {
|
||||||
|
|
@ -64,6 +69,7 @@ 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.status(HttpStatus.CREATED).body(matchService.createMatch(match))
|
||||||
|
|
@ -71,12 +77,14 @@ class MatchRestController(private val matchService: MatchService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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))
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
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.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.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.PathVariable
|
||||||
|
|
@ -16,6 +18,10 @@ import org.springframework.web.bind.annotation.RestController
|
||||||
@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:8080"
|
||||||
|
}
|
||||||
|
|
||||||
// Lister tous les joueurs
|
// Lister tous les joueurs
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
fun getAll(): ResponseEntity<List<PlayerBean>> {
|
fun getAll(): ResponseEntity<List<PlayerBean>> {
|
||||||
|
|
@ -47,18 +53,21 @@ class PlayerRestController(private val playerService: PlayerService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter un joueur
|
// Ajouter un joueur
|
||||||
|
@CrossOrigin(origins = [URL_ORIGIN])
|
||||||
@PostMapping("/create-player")
|
@PostMapping("/create-player")
|
||||||
fun createPlayer(@RequestBody 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
|
||||||
|
@CrossOrigin(origins = [URL_ORIGIN])
|
||||||
@PutMapping("/update-player/{id}")
|
@PutMapping("/update-player/{id}")
|
||||||
fun updatePlayer(@PathVariable id: Long, @RequestBody player: PlayerBean): ResponseEntity<Int> {
|
fun updatePlayer(@PathVariable id: Long, @RequestBody player: PlayerBean): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(playerService.updatePlayer(id, player))
|
return ResponseEntity.ok(playerService.updatePlayer(id, player))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer un joueur
|
// Supprimer un joueur
|
||||||
|
@CrossOrigin(origins = [URL_ORIGIN])
|
||||||
@DeleteMapping("/delete-player/{id}")
|
@DeleteMapping("/delete-player/{id}")
|
||||||
fun deletePlayer(@PathVariable id: Long): ResponseEntity<Int> {
|
fun deletePlayer(@PathVariable id: Long): ResponseEntity<Int> {
|
||||||
return ResponseEntity.ok(playerService.deletePlayerById(id))
|
return ResponseEntity.ok(playerService.deletePlayerById(id))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package fr.teamflash.fencerjudgeback.restControllers
|
||||||
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
import fr.teamflash.fencerjudgeback.entities.RefereeBean
|
||||||
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.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.PathVariable
|
||||||
|
|
@ -16,6 +17,10 @@ import org.springframework.web.bind.annotation.RestController
|
||||||
@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:8080"
|
||||||
|
}
|
||||||
|
|
||||||
// Lister tous les arbitres
|
// Lister tous les arbitres
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
fun getAll() : ResponseEntity<List<RefereeBean>> {
|
fun getAll() : ResponseEntity<List<RefereeBean>> {
|
||||||
|
|
@ -47,18 +52,21 @@ class RefereeRestController(private val refereeService: RefereeService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue