diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/PlayerWebSocketConfig.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/PlayerWebSocketConfig.kt deleted file mode 100644 index 012e601..0000000 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/PlayerWebSocketConfig.kt +++ /dev/null @@ -1,30 +0,0 @@ -package fr.teamflash.fencerjudgeback.config - -import org.springframework.context.annotation.Configuration -import org.springframework.messaging.simp.config.MessageBrokerRegistry -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker -import org.springframework.web.socket.config.annotation.StompEndpointRegistry -import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer - -const val CHANNEL_PLAYER_NAME: String = "/ws/topic/match" - -@Configuration -@EnableWebSocketMessageBroker -open class PlayerWebSocketConfig : WebSocketMessageBrokerConfigurer { - - override fun configureMessageBroker(registry: MessageBrokerRegistry) { - // Enable a simple memory-based message broker to send messages to clients - // Prefix for messages FROM server TO client - registry.enableSimpleBroker(CHANNEL_PLAYER_NAME) - - // Prefix for messages FROM client TO server - registry.setApplicationDestinationPrefixes("/ws") - } - - override fun registerStompEndpoints(registry: StompEndpointRegistry) { - // Register the "/ws" endpoint, enabling SockJS fallback options - registry.addEndpoint("/ws/players-app") - .setAllowedOriginPatterns("*") // Allow connections from any origin (adjust for production) - .withSockJS() - } -} \ No newline at end of file diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/RefereeWebSocketConfig.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/RefereeWebSocketConfig.kt deleted file mode 100644 index 9d4cf59..0000000 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/RefereeWebSocketConfig.kt +++ /dev/null @@ -1,30 +0,0 @@ -package fr.teamflash.fencerjudgeback.config - -import org.springframework.context.annotation.Configuration -import org.springframework.messaging.simp.config.MessageBrokerRegistry -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker -import org.springframework.web.socket.config.annotation.StompEndpointRegistry -import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer - -const val CHANNEL_REFEREE_NAME: String = "/ws/topic/referee" - -@Configuration -@EnableWebSocketMessageBroker -open class RefereeWebSocketConfig : WebSocketMessageBrokerConfigurer { - - override fun configureMessageBroker(registry: MessageBrokerRegistry) { - // Enable a simple memory-based message broker to send messages to clients - // Prefix for messages FROM server TO client - registry.enableSimpleBroker(CHANNEL_REFEREE_NAME) - - // Prefix for messages FROM client TO server - registry.setApplicationDestinationPrefixes("/ws") - } - - override fun registerStompEndpoints(registry: StompEndpointRegistry) { - // Register the "/ws" endpoint, enabling SockJS fallback options - registry.addEndpoint("/ws/referees-app") - .setAllowedOriginPatterns("*") // Allow connections from any origin (adjust for production) - .withSockJS() - } -} \ No newline at end of file diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/WebSocketConfig.kt similarity index 86% rename from FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt rename to FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/WebSocketConfig.kt index 5138d75..341b6f1 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/MatchWebSocketConfig.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/config/WebSocketConfig.kt @@ -6,16 +6,16 @@ import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBr import org.springframework.web.socket.config.annotation.StompEndpointRegistry import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer -const val CHANNEL_MATCH_NAME: String = "/ws/topic/match" +const val CHANNEL_NAME: String = "/ws/topic" @Configuration @EnableWebSocketMessageBroker -open class MatchWebSocketConfig : WebSocketMessageBrokerConfigurer { +open class WebSocketConfig : WebSocketMessageBrokerConfigurer { override fun configureMessageBroker(registry: MessageBrokerRegistry) { // Enable a simple memory-based message broker to send messages to clients // Prefix for messages FROM server TO client - registry.enableSimpleBroker(CHANNEL_MATCH_NAME) + registry.enableSimpleBroker(CHANNEL_NAME) // Prefix for messages FROM client TO server registry.setApplicationDestinationPrefixes("/ws") diff --git a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchBean.kt b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchBean.kt index 87ccf3e..0f95236 100644 --- a/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchBean.kt +++ b/FencerJudgeBack/src/main/kotlin/fr/teamflash/fencerjudgeback/entities/MatchBean.kt @@ -15,7 +15,7 @@ data class MatchBean( @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "match_sequence") @SequenceGenerator(name = "match_sequence", sequenceName = "match_seq", allocationSize = 1) - var id:Long?=null, + val id:Long?=null, val weapon:String?=null, val country:String?=null, val city:String?=null, 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 3ba9c54..1e5f24b 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.getAll") + println("MatchService.getMatchs") return matchRepository.findAll() } // Obtenir un match par id (public) fun getById(id: Long?): MatchBean? { - println("MatchService.getById : $id") + println("MatchService.getMatchById : $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.getByPlayers : $player1ID - $player2ID") + println("MatchService.getMatchByPlayers : $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 410efa8..218a1cb 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.getAll") + println("RefereeService.getReferees") return refereeRepository.findAll() } // Obtenir un arbitre par id (public) fun getById(id:Long?) : RefereeBean? { - println("RefereeService.getById : $id") + println("RefereeService.getRefereeById : $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.getByName : $name") + println("RefereeService.getRefereeByName : $name") return refereeRepository.findAll().filter{ it.name == name } } // Obtenir un ou plusieurs arbitre(s) par prénom fun getByFirstName(firstName:String): List? { - println("RefereeService.getByFirstName : $firstName") + println("RefereeService.getRefereeByFirstName : $firstName") return refereeRepository.findAll().filter{ it.firstName == firstName } } // Obtenir un ou plusieurs arbitre(s) par qualification fun getByQualification(qualification:String): List? { - println("RefereeService.getByQualification : $qualification") + println("RefereeService.getRefereeByQualification : $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 1b86f73..e75518d 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 @@ -1,6 +1,6 @@ package fr.teamflash.fencerjudgeback.websocket.controllers -import fr.teamflash.fencerjudgeback.config.CHANNEL_MATCH_NAME +import fr.teamflash.fencerjudgeback.config.CHANNEL_NAME import fr.teamflash.fencerjudgeback.entities.MatchBean import fr.teamflash.fencerjudgeback.services.MatchService import fr.teamflash.fencerjudgeback.websocket.models.MatchUpdateMessage @@ -9,7 +9,6 @@ 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 @@ -20,7 +19,6 @@ class MatchWebSocketController( private val messagingTemplate: SimpMessagingTemplate ) { - private var mainId:Long? = 1 private val messageHistory = ArrayList() @MessageMapping("/all") @@ -30,7 +28,7 @@ class MatchWebSocketController( // Envoyer la liste des messages sur le channel //Si la variable est dans le même package il faut enlever WebSocketConfig. - messagingTemplate.convertAndSend(CHANNEL_MATCH_NAME, messageHistory) + messagingTemplate.convertAndSend(CHANNEL_NAME, messageHistory) } /** @@ -71,14 +69,13 @@ class MatchWebSocketController( @EventListener fun handleWebSocketSubscribeListener(event: SessionSubscribeEvent) { val headerAccessor = StompHeaderAccessor.wrap(event.message) - if (CHANNEL_MATCH_NAME == headerAccessor.destination) { - messagingTemplate.convertAndSend(CHANNEL_MATCH_NAME, messageHistory) + if (CHANNEL_NAME == headerAccessor.destination) { + messagingTemplate.convertAndSend(CHANNEL_NAME, messageHistory) println("Lancement...") } } - @MessageMapping("/plusPoint/{playerId}") - fun addPoint(match:MatchBean, @PathVariable playerId:Long) { + fun addPoint(match:MatchBean, playerId:Long) { when (playerId) { match.player1ID -> match.score1 += 1 match.player2ID -> match.score2 += 1 @@ -87,8 +84,7 @@ class MatchWebSocketController( broadcastMatchUpdate(match) } - @MessageMapping("/minusPoint/{playerId}") - fun minusPoint(match:MatchBean, @PathVariable playerId:Long) { + fun minusPoint(match:MatchBean, playerId:Long) { when (playerId) { match.player1ID -> if (match.score1 > 0) match.score1 -= 1 match.player2ID -> if (match.score2 > 0) match.score2 -= 1 @@ -99,10 +95,8 @@ class MatchWebSocketController( @MessageMapping("/add") fun addMatchtoMainList(match:MatchBean) { - match.id = mainId; matchService.addMatch(match) messageHistory.add(match) broadcastMatchUpdate(match, MatchUpdateMessage.UpdateType.NEW_MATCH) - mainId = mainId?.plus(1) } } \ 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 34c7a94..2b21601 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,5 +1,6 @@ package fr.teamflash.fencerjudgeback.websocket.controllers +import fr.teamflash.fencerjudgeback.config.CHANNEL_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/testPlayerMatchWebSocketHTML.html b/FencerJudgeBack/src/main/resources/static/testPlayerMatchWebSocketHTML.html deleted file mode 100644 index 15b617a..0000000 --- a/FencerJudgeBack/src/main/resources/static/testPlayerMatchWebSocketHTML.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Test WebSocket Match - - - - -

Test WebSocket Match

- -
Connexion...
- -
- - - - -
- -
- - - -
- - - - - - - - - - diff --git a/FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html b/FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html deleted file mode 100644 index 87d370b..0000000 --- a/FencerJudgeBack/src/main/resources/static/testRefereeWebSocketHTML.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Test WebSocket Match - - - - -

Test WebSocket Match

- -
Connexion...
- -
- - - - -
- -
- - - -
- - - - - - - - - - diff --git a/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html b/FencerJudgeBack/src/main/resources/static/testWebSocketHTML.html similarity index 98% rename from FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html rename to FencerJudgeBack/src/main/resources/static/testWebSocketHTML.html index 2819a41..1009354 100644 --- a/FencerJudgeBack/src/main/resources/static/testMatchWebSocketHTML.html +++ b/FencerJudgeBack/src/main/resources/static/testWebSocketHTML.html @@ -48,7 +48,7 @@