diff --git a/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_16.xml b/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_16.xml
new file mode 100644
index 0000000..b969cc3
--- /dev/null
+++ b/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_16.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ceff811..55ff008 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,527 +1,482 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
respon
topic
data
greeting
GreetingContro
hello
HelloMess
Update data
update
savePilot
List
current
bestLap
updateAll
coucou
+ 8080
videoProblems
+ Paris
+
+ C:\Users\Mathis\Documents\EPFL\essai WS\backend\springboot-stomp-websocket\src\main
+
+
+
+
-
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
1563541468370
1563541468370
-
+
+
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
1.8
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 448b9a8..ce06224 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,91 +1,97 @@
4.0.0
org.springframework
springboot-stomp-websocket
0.1.0
org.springframework.boot
spring-boot-starter-parent
2.1.4.RELEASE
org.springframework.boot
spring-boot-starter-websocket
org.webjars
webjars-locator-core
org.webjars
sockjs-client
1.0.2
org.webjars
stomp-websocket
2.3.3
org.webjars
bootstrap
3.3.7
org.webjars
jquery
3.1.0
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-data-jpa
com.h2database
h2
1.4.199
org.projectlombok
lombok
1.18.6
org.springframework.data
spring-data-rest-core
3.1.2.RELEASE
com.fasterxml.jackson.core
jackson-databind
2.9.8
+
+ mysql
+ mysql-connector-java
+ 8.0.16
+
+
1.8
org.springframework.boot
spring-boot-maven-plugin
diff --git a/springboot-stomp-websocket.iml b/springboot-stomp-websocket.iml
index 9a5d46f..fd80ac8 100644
--- a/springboot-stomp-websocket.iml
+++ b/springboot-stomp-websocket.iml
@@ -1,116 +1,117 @@
+
\ No newline at end of file
diff --git a/src/main/java/net/javaguides/springboot/websocket/Application.java b/src/main/java/net/javaguides/springboot/websocket/Application.java
index 799526f..b676a00 100644
--- a/src/main/java/net/javaguides/springboot/websocket/Application.java
+++ b/src/main/java/net/javaguides/springboot/websocket/Application.java
@@ -1,61 +1,13 @@
package net.javaguides.springboot.websocket;
-import net.javaguides.springboot.websocket.model.Pilot;
-import net.javaguides.springboot.websocket.repository.PilotRepository;
-import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-
-import java.util.stream.Stream;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
- private int judge = 0;
- private int id = 8;
-
- @Bean
- ApplicationRunner init(PilotRepository pilotRepository) {
- return args -> {
-
- /*
-
- id = 8;
-
- judge = 0;
- Stream.of("azefkjl", "Caover", "azlkef", "azek").forEach(name -> {
- judge += 1;
- id += 1;
- Pilot pilot = new Pilot();
- pilot.setNickname(name);
- pilot.setCurrent("current");
- pilot.setRun("2");
- pilot.setSeat(judge);
- pilot.setPilotId(id);
- pilotRepository.save(pilot);
- });
-
- judge = 0;
- Stream.of("Darkex", "Captain Vanover", "Remco", "BLS").forEach(name -> {
- judge += 1;
- id += 1;
- Pilot pilot = new Pilot();
- pilot.setNickname(name);
- pilot.setCurrent("passed");
- pilot.setRun("1");
- pilot.setSeat(judge);
- pilot.setPilotId(id);
- pilotRepository.save(pilot);
- });
-
- pilotRepository.findAll().forEach(System.out::println);
-
- */
- };
- }
}
diff --git a/src/main/java/net/javaguides/springboot/websocket/controller/CurrentPilotsController.java b/src/main/java/net/javaguides/springboot/websocket/controller/PilotsController.java
similarity index 62%
rename from src/main/java/net/javaguides/springboot/websocket/controller/CurrentPilotsController.java
rename to src/main/java/net/javaguides/springboot/websocket/controller/PilotsController.java
index 55ad0a7..e49035b 100644
--- a/src/main/java/net/javaguides/springboot/websocket/controller/CurrentPilotsController.java
+++ b/src/main/java/net/javaguides/springboot/websocket/controller/PilotsController.java
@@ -1,49 +1,83 @@
package net.javaguides.springboot.websocket.controller;
import net.javaguides.springboot.websocket.model.Pilot;
import net.javaguides.springboot.websocket.repository.PilotRepository;
import org.springframework.web.bind.annotation.*;
-
-import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.Collectors;
+/**
+ * Manage all pilots
+ */
@RestController
-public class CurrentPilotsController {
+public class PilotsController {
private PilotRepository repository;
- public CurrentPilotsController(PilotRepository repository) {
+ public PilotsController(PilotRepository repository) {
this.repository = repository;
}
+ /**
+ * Get current pilots from bdd
+ * @return list of current pilots
+ */
@GetMapping("/getCurrentPilots")
@CrossOrigin
public Collection getCurrentPilots() {
return repository.findAll().stream()
.filter(this::isCurrent)
.collect(Collectors.toList());
}
+ /**
+ * Filter on pilot list
+ * @param pilot
+ * @return pilot only if it is a current pilot
+ */
private boolean isCurrent(Pilot pilot) {
return pilot.getCurrent().equals("current");
}
+ /**
+ * Get passed pilots from bdd
+ * @return list of passed pilots
+ */
@GetMapping("/getPassedPilots")
@CrossOrigin
public Collection getPassedPilots() {
return repository.findAll().stream()
.filter(this::isPassed)
.collect(Collectors.toList());
}
+ /**
+ * Filter on pilot list
+ * @param pilot
+ * @return pilot only if it is a passed pilot
+ */
private boolean isPassed(Pilot pilot) {
return pilot.getCurrent().equals("passed");
}
+ /**
+ * Save pilot in bdd
+ * @param pilot
+ */
@PostMapping(path = "/savePilot", consumes = "application/json", produces = "application/json")
@CrossOrigin
public void savePilot(@RequestBody Pilot pilot) {
repository.save(pilot);
System.out.println(pilot);
}
+
+ /**
+ * Delete all pilots from bdd
+ * @return
+ */
+ @GetMapping("/clearPilots")
+ @CrossOrigin
+ public boolean clearPilots() {
+ repository.deleteAll();
+ return true;
+ }
}
diff --git a/src/main/java/net/javaguides/springboot/websocket/controller/ThirdApiController.java b/src/main/java/net/javaguides/springboot/websocket/controller/ThirdApiController.java
new file mode 100644
index 0000000..f9b6e14
--- /dev/null
+++ b/src/main/java/net/javaguides/springboot/websocket/controller/ThirdApiController.java
@@ -0,0 +1,53 @@
+package net.javaguides.springboot.websocket.controller;
+
+import net.javaguides.springboot.websocket.model.ThirdApi;
+import net.javaguides.springboot.websocket.repository.ThirdApiRepository;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Collection;
+
+/**
+ * Manage the API in bdd
+ */
+@RestController
+public class ThirdApiController {
+ private ThirdApiRepository repository;
+
+ public ThirdApiController(ThirdApiRepository repository) {
+ this.repository = repository;
+ }
+
+ /**
+ * GetThirdApi
+ * @return the Api from bdd
+ */
+ @GetMapping("/getThirdApi")
+ @CrossOrigin
+ public Collection getThirdApi() {
+ return repository.findAll();
+ }
+
+ /**
+ * Delete the api in bdd and save new api
+ * @param api
+ */
+ @PostMapping(path = "/saveThirdApi", consumes = MediaType.APPLICATION_JSON_VALUE , produces = "application/json")
+ @CrossOrigin
+ public void saveThirdApi(@RequestBody ThirdApi api) {
+ repository.deleteAll();
+ repository.save(api);
+ System.out.println(api);
+ }
+
+ /**
+ * Delete api in bdd
+ * @return true
+ */
+ @GetMapping("/deleteThirdApi")
+ @CrossOrigin
+ public boolean deleteThirdApi() {
+ repository.deleteAll();
+ return true;
+ }
+}
diff --git a/src/main/java/net/javaguides/springboot/websocket/controller/UpdateController.java b/src/main/java/net/javaguides/springboot/websocket/controller/UpdateController.java
index 843bc4e..c5d22b7 100644
--- a/src/main/java/net/javaguides/springboot/websocket/controller/UpdateController.java
+++ b/src/main/java/net/javaguides/springboot/websocket/controller/UpdateController.java
@@ -1,21 +1,34 @@
package net.javaguides.springboot.websocket.controller;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
+/**
+ * Update controller manage websocket message to notify clients
+ */
@Controller
public class UpdateController {
+ /**
+ * Receive "updateCurrent" message and notify all connected client "updateCurrent"
+ * @return "updateCurrent"
+ * @throws Exception
+ */
@MessageMapping("/updateCurrent")
@SendTo("/data/update")
public String updateCurrent() throws Exception {
return "updateCurrent";
}
+ /**
+ * Receive "updatePassed" message and notify all connected client "updatePassed"
+ * @return "updatePassed"
+ * @throws Exception
+ */
@MessageMapping("/updatePassed")
@SendTo("/data/update")
public String updatePassed() throws Exception {
return "updatePassed";
}
}
diff --git a/src/main/java/net/javaguides/springboot/websocket/model/ThirdApi.java b/src/main/java/net/javaguides/springboot/websocket/model/ThirdApi.java
new file mode 100644
index 0000000..e7aabf3
--- /dev/null
+++ b/src/main/java/net/javaguides/springboot/websocket/model/ThirdApi.java
@@ -0,0 +1,19 @@
+package net.javaguides.springboot.websocket.model;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+@Data
+@NoArgsConstructor
+public class ThirdApi {
+ @Id
+ @GeneratedValue
+ private Long id;
+ private String url;
+}
diff --git a/src/main/java/net/javaguides/springboot/websocket/repository/ThirdApiRepository.java b/src/main/java/net/javaguides/springboot/websocket/repository/ThirdApiRepository.java
new file mode 100644
index 0000000..b5ae14d
--- /dev/null
+++ b/src/main/java/net/javaguides/springboot/websocket/repository/ThirdApiRepository.java
@@ -0,0 +1,9 @@
+package net.javaguides.springboot.websocket.repository;
+
+import net.javaguides.springboot.websocket.model.ThirdApi;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
+
+@RepositoryRestResource
+public interface ThirdApiRepository extends JpaRepository {
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..edf3b57
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1,15 @@
+server.port 8080
+
+spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
+spring.jpa.hibernate.ddl-auto=update
+spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/myrace?serverTimezone=Europe/Paris
+spring.datasource.username=root
+spring.datasource.password=
+
+
+
+
+# Configurations H2
+spring.jpa.show-sql=true
+spring.h2.console.enabled=true
\ No newline at end of file