merge back-lucien with feature/back #3
8 changed files with 63 additions and 51 deletions
|
|
@ -15,10 +15,10 @@ open class MatchWebSocketConfig : 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_NAME)
|
||||
registry.enableSimpleBroker(CHANNEL_MATCH_NAME)
|
||||
|
||||
// Prefix for messages FROM client TO server
|
||||
registry.setApplicationDestinationPrefixes("/ws")
|
||||
registry.setApplicationDestinationPrefixes("/ws/matches")
|
||||
}
|
||||
|
||||
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
package fr.teamflash.fencerjudgeback.entities
|
||||
|
||||
data class MatchUpdateBean(val match: MatchBean?=null, val playerId:Long?=null)
|
||||
|
|
@ -6,10 +6,4 @@ import org.springframework.stereotype.Repository
|
|||
|
||||
@Repository
|
||||
interface MatchRepository: JpaRepository<MatchBean, Long> {
|
||||
fun getAll(): List<MatchBean> {
|
||||
return listOf(
|
||||
MatchBean(1, "Fleuret", "France", "Paris", 1, 2, 3, 10, 12, "16-08-2004", "terminé")
|
||||
)
|
||||
// return this.findAll()
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ class MatchService(
|
|||
// Obtenir tous les matchs (public)
|
||||
fun getAll() : List<MatchBean> {
|
||||
println("MatchService.getMatchs")
|
||||
return matchRepository.getAll()
|
||||
return matchRepository.findAll()
|
||||
}
|
||||
|
||||
// Obtenir un match par id (public)
|
||||
|
|
@ -33,7 +33,7 @@ class MatchService(
|
|||
// Obtenir un ou plusieurs match(s) par joueurs (id) (public)
|
||||
fun getByPlayers(player1ID: Long?, player2ID: Long?): List<MatchBean> {
|
||||
println("MatchService.getMatchByPlayers : $player1ID - $player2ID")
|
||||
return matchRepository.getAll().filter { it.player1ID == player1ID && it.player2ID == player2ID }
|
||||
return matchRepository.findAll().filter { it.player1ID == player1ID && it.player2ID == player2ID }
|
||||
}
|
||||
|
||||
// Ajouter un match (admin)
|
||||
|
|
@ -81,14 +81,14 @@ class MatchService(
|
|||
fun getMatchesByCity(city: String): List<MatchBean>? {
|
||||
println("MatchService.getMatchesByCity : $city")
|
||||
|
||||
return matchRepository.getAll()
|
||||
return matchRepository.findAll()
|
||||
.filter { it.city == city }
|
||||
}
|
||||
|
||||
fun getMatchesByCountry(country: String): List<MatchBean>? {
|
||||
println("MatchService.getMatchesByCountry : $country")
|
||||
|
||||
return matchRepository.getAll()
|
||||
return matchRepository.findAll()
|
||||
.filter { it.country == country }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ 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
|
||||
|
|
@ -9,12 +10,9 @@ 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
|
||||
|
|
@ -73,22 +71,17 @@ class MatchWebSocketController(
|
|||
val headerAccessor = StompHeaderAccessor.wrap(event.message)
|
||||
if (CHANNEL_MATCH_NAME == headerAccessor.destination) {
|
||||
messagingTemplate.convertAndSend(CHANNEL_MATCH_NAME, messageHistory)
|
||||
println("Lancement...")
|
||||
println("Lancement du WebSocket")
|
||||
}
|
||||
}
|
||||
|
||||
@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/{playerId}")
|
||||
fun minusPoint(match:MatchBean, @PathVariable playerId:Long) {
|
||||
@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
|
||||
|
|
@ -96,6 +89,22 @@ class MatchWebSocketController(
|
|||
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("/add")
|
||||
fun addMatchtoMainList(match:MatchBean) {
|
||||
|
|
@ -104,5 +113,6 @@ class MatchWebSocketController(
|
|||
messageHistory.add(match)
|
||||
broadcastMatchUpdate(match, MatchUpdateMessage.UpdateType.NEW_MATCH)
|
||||
mainId = mainId?.plus(1)
|
||||
println("Ajout du match $match.id en bdd")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package fr.teamflash.fencerjudgeback.websocket.controllers
|
||||
|
||||
import fr.teamflash.fencerjudgeback.config.CHANNEL_NAME
|
||||
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
|
||||
|
|
|
|||
|
|
@ -29,15 +29,14 @@
|
|||
<div id="messageArea">Connexion...</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" id="matchId" placeholder="Match ID">
|
||||
<input type="number" id="player1Id" placeholder="Joueur 1 ID">
|
||||
<input type="number" id="player2Id" placeholder="Joueur 2 ID">
|
||||
<input type="number" id="refereeId" placeholder="Arbitre ID">
|
||||
<input type="number" id="player1Id" placeholder="Joueur 1 ID" value="2">
|
||||
<input type="number" id="player2Id" placeholder="Joueur 2 ID" value="2">
|
||||
<input type="number" id="refereeId" placeholder="Arbitre ID" value="2">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" id="score1" placeholder="Score Joueur 1">
|
||||
<input type="number" id="score2" placeholder="Score Joueur 2">
|
||||
<input type="number" id="score1" placeholder="Score Joueur 1" value="2">
|
||||
<input type="number" id="score2" placeholder="Score Joueur 2" value="14">
|
||||
<input type="datetime-local" id="matchDate">
|
||||
</div>
|
||||
|
||||
|
|
@ -63,7 +62,7 @@
|
|||
|
||||
function sendMatch() {
|
||||
const match = {
|
||||
matchId: parseInt(document.getElementById("matchId").value),
|
||||
id: 1,
|
||||
player1Id: parseInt(document.getElementById("player1Id").value),
|
||||
player2Id: parseInt(document.getElementById("player2Id").value),
|
||||
refereeId: parseInt(document.getElementById("refereeId").value),
|
||||
|
|
@ -73,12 +72,14 @@
|
|||
};
|
||||
|
||||
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.matchId}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`;
|
||||
div.textContent = `Match ${match.id}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`;
|
||||
area.appendChild(div);
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -29,15 +29,14 @@
|
|||
<div id="messageArea">Connexion...</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" id="matchId" placeholder="Match ID">
|
||||
<input type="number" id="player1Id" placeholder="Joueur 1 ID">
|
||||
<input type="number" id="player2Id" placeholder="Joueur 2 ID">
|
||||
<input type="number" id="refereeId" placeholder="Arbitre ID">
|
||||
<input type="number" id="player1Id" placeholder="Joueur 1 ID" value="2">
|
||||
<input type="number" id="player2Id" placeholder="Joueur 2 ID" value="2">
|
||||
<input type="number" id="refereeId" placeholder="Arbitre ID" value="2">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" id="score1" placeholder="Score Joueur 1">
|
||||
<input type="number" id="score2" placeholder="Score Joueur 2">
|
||||
<input type="number" id="score1" placeholder="Score Joueur 1" value="2">
|
||||
<input type="number" id="score2" placeholder="Score Joueur 2" value="14">
|
||||
<input type="datetime-local" id="matchDate">
|
||||
</div>
|
||||
|
||||
|
|
@ -47,8 +46,8 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>
|
||||
|
||||
<script>
|
||||
const stompClient = Stomp.over(new SockJS('/ws/referees-app'));
|
||||
const channel = "/ws/topic/referee";
|
||||
const stompClient = Stomp.over(new SockJS('/ws/matches-app'));
|
||||
const channel = "/ws/topic/match";
|
||||
|
||||
stompClient.connect({}, function () {
|
||||
stompClient.subscribe(channel, function (message) {
|
||||
|
|
@ -63,7 +62,7 @@
|
|||
|
||||
function sendMatch() {
|
||||
const match = {
|
||||
matchId: parseInt(document.getElementById("matchId").value),
|
||||
id: 1,
|
||||
player1Id: parseInt(document.getElementById("player1Id").value),
|
||||
player2Id: parseInt(document.getElementById("player2Id").value),
|
||||
refereeId: parseInt(document.getElementById("refereeId").value),
|
||||
|
|
@ -72,13 +71,18 @@
|
|||
date: document.getElementById("matchDate").value
|
||||
};
|
||||
|
||||
stompClient.send("/ws/matches/add", {}, JSON.stringify(match));
|
||||
stompClient.send("/ws/matches/addPoint", {}, JSON.stringify({
|
||||
match: match,
|
||||
playerId: match.player1Id
|
||||
}));
|
||||
|
||||
displayMessage(match)
|
||||
}
|
||||
|
||||
function displayMessage(match) {
|
||||
const area = document.getElementById("messageArea");
|
||||
const div = document.createElement("div");
|
||||
div.textContent = `Match ${match.matchId}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`;
|
||||
div.textContent = `Match ${match.id}: ${match.player1Id} (${match.score1}) vs ${match.player2Id} (${match.score2})`;
|
||||
area.appendChild(div);
|
||||
}
|
||||
</script>
|
||||
Loading…
Add table
Reference in a new issue