diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt index 6fc3650..5138d75 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt @@ -18,7 +18,7 @@ open class MatchWebSocketConfig : WebSocketMessageBrokerConfigurer { registry.enableSimpleBroker(CHANNEL_MATCH_NAME) // Prefix for messages FROM client TO server - registry.setApplicationDestinationPrefixes("/ws/matches") + registry.setApplicationDestinationPrefixes("/ws") } override fun registerStompEndpoints(registry: StompEndpointRegistry) { diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchUpdateBean.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchUpdateBean.kt deleted file mode 100644 index 16059ac..0000000 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchUpdateBean.kt +++ /dev/null @@ -1,3 +0,0 @@ -package fr.teamflash.fencerjudgeback.entities - -data class MatchUpdateBean(val match: MatchBean?=null, val playerId:Long?=null) \ No newline at end of file diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt index 1e5f24b..3ba9c54 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/MatchService.kt @@ -14,13 +14,13 @@ class MatchService( ) { // Obtenir tous les matchs (public) fun getAll() : List { - println("MatchService.getMatchs") + println("MatchService.getAll") return matchRepository.findAll() } // Obtenir un match par id (public) fun getById(id: Long?): MatchBean? { - println("MatchService.getMatchById : $id") + println("MatchService.getById : $id") if (id == null) { println("MatchService.getMatchById : Match not found") @@ -32,7 +32,7 @@ class MatchService( // Obtenir un ou plusieurs match(s) par joueurs (id) (public) fun getByPlayers(player1ID: Long?, player2ID: Long?): List { - println("MatchService.getMatchByPlayers : $player1ID - $player2ID") + println("MatchService.getByPlayers : $player1ID - $player2ID") return matchRepository.findAll().filter { it.player1ID == player1ID && it.player2ID == player2ID } } diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/RefereeService.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/RefereeService.kt index 218a1cb..410efa8 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/RefereeService.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/services/RefereeService.kt @@ -15,13 +15,13 @@ class RefereeService( ) { // Obtenir tous les arbitres (public) fun getAll(): List { - println("RefereeService.getReferees") + println("RefereeService.getAll") return refereeRepository.findAll() } // Obtenir un arbitre par id (public) fun getById(id:Long?) : RefereeBean? { - println("RefereeService.getRefereeById : $id") + println("RefereeService.getById : $id") if (id == null) { return null @@ -32,19 +32,19 @@ class RefereeService( // Obtenir un ou plusieurs arbitre(s) par nom (public) fun getByName(name:String): List? { - println("RefereeService.getRefereeByName : $name") + println("RefereeService.getByName : $name") return refereeRepository.findAll().filter{ it.name == name } } // Obtenir un ou plusieurs arbitre(s) par prénom fun getByFirstName(firstName:String): List? { - println("RefereeService.getRefereeByFirstName : $firstName") + println("RefereeService.getByFirstName : $firstName") return refereeRepository.findAll().filter{ it.firstName == firstName } } // Obtenir un ou plusieurs arbitre(s) par qualification fun getByQualification(qualification:String): List? { - println("RefereeService.getRefereeByQualification : $qualification") + println("RefereeService.getByQualification : $qualification") return refereeRepository.findAll().filter{ it.qualification == qualification } } diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/MatchWebSocketController.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/MatchWebSocketController.kt index bee6a2f..1b86f73 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/MatchWebSocketController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/MatchWebSocketController.kt @@ -2,7 +2,6 @@ package fr.teamflash.fencerjudgeback.websocket.controllers import fr.teamflash.fencerjudgeback.config.CHANNEL_MATCH_NAME import fr.teamflash.fencerjudgeback.entities.MatchBean -import fr.teamflash.fencerjudgeback.entities.MatchUpdateBean import fr.teamflash.fencerjudgeback.services.MatchService import fr.teamflash.fencerjudgeback.websocket.models.MatchUpdateMessage import org.springframework.context.event.EventListener @@ -10,9 +9,12 @@ import org.springframework.messaging.handler.annotation.MessageMapping import org.springframework.messaging.simp.SimpMessagingTemplate import org.springframework.messaging.simp.stomp.StompHeaderAccessor import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.socket.messaging.SessionSubscribeEvent @Controller +@RequestMapping("/ws/matches") class MatchWebSocketController( private val matchService: MatchService, private val messagingTemplate: SimpMessagingTemplate @@ -71,40 +73,29 @@ class MatchWebSocketController( val headerAccessor = StompHeaderAccessor.wrap(event.message) if (CHANNEL_MATCH_NAME == headerAccessor.destination) { messagingTemplate.convertAndSend(CHANNEL_MATCH_NAME, messageHistory) - println("Lancement du WebSocket") + println("Lancement...") } } - @MessageMapping("/plusPoint") - fun addPoint(matchUpdateBean: MatchUpdateBean) { - val playerId = matchUpdateBean.playerId - val match = matchUpdateBean.match - print("plus") - if (match != null) { - print("minus") - when (playerId) { - match.player1ID -> if (match.score1 > 0) match.score1 -= 1 - match.player2ID -> if (match.score2 > 0) match.score2 -= 1 - } - matchService.updateMatch(match.id, match) - broadcastMatchUpdate(match) + @MessageMapping("/plusPoint/{playerId}") + fun addPoint(match:MatchBean, @PathVariable playerId:Long) { + when (playerId) { + match.player1ID -> match.score1 += 1 + match.player2ID -> match.score2 += 1 } + matchService.updateMatch(match.id, match) + broadcastMatchUpdate(match) } - @MessageMapping("/minusPoint") - fun minusPoint(matchUpdateBean: MatchUpdateBean) { - val playerId = matchUpdateBean.playerId - val match = matchUpdateBean.match - print("minus") - if (match != null) { - when (playerId) { - match.player1ID -> if (match.score1 > 0) match.score1 -= 1 - match.player2ID -> if (match.score2 > 0) match.score2 -= 1 - } - matchService.updateMatch(match.id, match) - broadcastMatchUpdate(match) - } + @MessageMapping("/minusPoint/{playerId}") + fun minusPoint(match:MatchBean, @PathVariable playerId:Long) { + when (playerId) { + match.player1ID -> if (match.score1 > 0) match.score1 -= 1 + match.player2ID -> if (match.score2 > 0) match.score2 -= 1 } + matchService.updateMatch(match.id, match) + broadcastMatchUpdate(match) + } @MessageMapping("/add") fun addMatchtoMainList(match:MatchBean) { @@ -113,6 +104,5 @@ class MatchWebSocketController( messageHistory.add(match) broadcastMatchUpdate(match, MatchUpdateMessage.UpdateType.NEW_MATCH) mainId = mainId?.plus(1) - println("Ajout du match $match.id en bdd") } } \ No newline at end of file diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/RefereeWebSocketController.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/RefereeWebSocketController.kt index 6064fda..34c7a94 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/RefereeWebSocketController.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/websocket/controllers/RefereeWebSocketController.kt @@ -1,6 +1,5 @@ package fr.teamflash.fencerjudgeback.websocket.controllers -import fr.teamflash.fencerjudgeback.config.CHANNEL_MATCH_NAME import fr.teamflash.fencerjudgeback.entities.RefereeBean import fr.teamflash.fencerjudgeback.services.RefereeService import fr.teamflash.fencerjudgeback.websocket.models.RefereeUpdateMessage diff --git a/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html b/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html index 05c5007..2819a41 100644 --- a/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html +++ b/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html @@ -29,14 +29,15 @@
Connexion...
- - - + + + +
- - + +
@@ -62,7 +63,7 @@ function sendMatch() { const match = { - id: 1, + matchId: parseInt(document.getElementById("matchId").value), player1Id: parseInt(document.getElementById("player1Id").value), player2Id: parseInt(document.getElementById("player2Id").value), refereeId: parseInt(document.getElementById("refereeId").value), @@ -72,14 +73,12 @@ }; stompClient.send("/ws/matches/add", {}, JSON.stringify(match)); - - displayMessage(match) } function displayMessage(match) { const area = document.getElementById("messageArea"); const div = document.createElement("div"); - div.textContent = `Match ${match.id}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`; + div.textContent = `Match ${match.matchId}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`; area.appendChild(div); } diff --git a/FencerJudgeBack/src/main/resources/static/testPlusOrMinusWebSocketHTML.html b/FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html similarity index 71% rename from FencerJudgeBack/src/main/resources/static/testPlusOrMinusWebSocketHTML.html rename to FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html index 05219fd..87d370b 100644 --- a/FencerJudgeBack/src/main/resources/static/testPlusOrMinusWebSocketHTML.html +++ b/FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html @@ -29,14 +29,15 @@
Connexion...
- - - + + + +
- - + +
@@ -46,8 +47,8 @@