diff --git a/curl.sh b/curl.sh new file mode 100755 index 0000000..96ba536 --- /dev/null +++ b/curl.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Basic integration tests using curl... + +curl -s --header "Accept: application/json" --header "Content-Type: application/json" \ + --request POST \ + --data '{ "type":"INDIVIDUAL","name":"Mon Tournoi", "shortName": "mon-tournoi", "startDate": "2023-05-10", "endDate": "2023-05-12", "country": "FR", "location": "Marseille", "online": false, "timeSystem": { "type": "fischer", "mainTime": "1200", "increment": "10" }, "pairing": { "type": "ROUNDROBIN" }, "rounds": 5 }' \ + http://localhost:8080/api/tour + +curl -s --header "Accept: application/json" http://localhost:8080/api/tour + +curl -s --header "Accept: application/json" http://localhost:8080/api/tour/1 + +curl -s --header "Accept: application/json" --header "Content-Type: application/json" \ + --request POST \ + --data '{ "name": "Burma", "firstname": "Nestor", "rating": 1600, "rank": -2, "country": "FR", "club": "13Ma" }' \ + http://localhost:8080/api/tour/1/part + +curl -s --header "Accept: application/json" http://localhost:8080/api/tour/1/part + +echo +echo + +curl -s --header "Last-Event-Id: 0" http://localhost:8080/events diff --git a/webapp/src/main/kotlin/org/jeudego/pairgoth/web/Event.kt b/webapp/src/main/kotlin/org/jeudego/pairgoth/web/Event.kt index 9ead03f..2f46f56 100644 --- a/webapp/src/main/kotlin/org/jeudego/pairgoth/web/Event.kt +++ b/webapp/src/main/kotlin/org/jeudego/pairgoth/web/Event.kt @@ -1,6 +1,7 @@ package org.jeudego.pairgoth.web import info.macias.sse.events.MessageEvent +import java.util.concurrent.atomic.AtomicLong enum class Event { tournamentAdded, @@ -15,8 +16,10 @@ enum class Event { ; companion object { + private val nextMessageId = AtomicLong(0) private val sse: SSEServlet by lazy { SSEServlet.getInstance() } private fun buildEvent(event: Event, data: T) = MessageEvent.Builder() + .setId("${nextMessageId.incrementAndGet()}".padStart(10, '0')) .setEvent(event.name) .setData(data.toString()) .build()