diff --git a/pom.xml b/pom.xml
index 3666117..e96ad4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
de.exodus-hn
excalibur-tour
- 0.0.1-SNAPSHOT
+ 0.1.0
diff --git a/src/main/java/de/exodus_hn/excalibur_tour/configurations/TourCodeHandshakeInterceptor.java b/src/main/java/de/exodus_hn/excalibur_tour/configurations/TourCodeHandshakeInterceptor.java
index 71de795..8ea6b24 100644
--- a/src/main/java/de/exodus_hn/excalibur_tour/configurations/TourCodeHandshakeInterceptor.java
+++ b/src/main/java/de/exodus_hn/excalibur_tour/configurations/TourCodeHandshakeInterceptor.java
@@ -25,10 +25,6 @@ public class TourCodeHandshakeInterceptor implements HandshakeInterceptor {
String tourCode = servletRequest.getServletRequest().getParameter("tourCode");
// Prüfen, ob der TourCode existiert und gültig ist
- if (tourCode != null && tourCode.equals("TESTTEST!")) {
- attributes.put("tourCode", tourCode);
- return true;
- }
if (tourCode != null && tourCodeService.getTourCodeByCode(tourCode) != null) {
// TourCode in den Session-Attributen für spätere Autorisierungen hinterlegen
attributes.put("tourCode", tourCode);
diff --git a/src/main/java/de/exodus_hn/excalibur_tour/controller/CodeController.java b/src/main/java/de/exodus_hn/excalibur_tour/controller/CodeController.java
index a50e2f7..6f8295b 100644
--- a/src/main/java/de/exodus_hn/excalibur_tour/controller/CodeController.java
+++ b/src/main/java/de/exodus_hn/excalibur_tour/controller/CodeController.java
@@ -10,6 +10,7 @@ import de.exodus_hn.excalibur_tour.services.RiddleService;
import de.exodus_hn.excalibur_tour.services.TourCodeService;
import de.exodus_hn.excalibur_tour.services.TourSessionService;
import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -26,6 +27,7 @@ public class CodeController {
private final TourSessionService tourSessionService;
private final RiddleService riddleService;
private final RiddleMapper riddleMapper;
+ private final RandomStringUtils randomStringUtils = RandomStringUtils.secure();
@GetMapping
public ResponseEntity check(@RequestParam() String code) {
@@ -34,8 +36,8 @@ public class CodeController {
}
TourCode t = tourCodeService.getTourCodeByCode(code);
if (t == null) {
- t = tourCodeService.addTourCode(code);
- System.out.println("DEBUG: Created TC " + t.getId());
+ /*t = tourCodeService.addTourCode(code);
+ System.out.println("DEBUG: Created TC " + t.getId());*/
return ResponseEntity.notFound().build();
}
LocalDateTime now = Utils.getDateTimeNow();
@@ -48,9 +50,9 @@ public class CodeController {
return ResponseEntity.notFound().build();
}
LocalDateTime heartbeat = t.getLastHeartbeatTimestamp();
- /*if (heartbeat != null && heartbeat.plus(3, ChronoUnit.MINUTES).isAfter(now)) {
+ if (heartbeat != null && heartbeat.plus(3, ChronoUnit.MINUTES).isAfter(now)) {
return ResponseEntity.notFound().build();
- }*/
+ }
t.setLastHeartbeatTimestamp(now);
tourCodeService.updateCode(t);
TourSession tourSession = tourSessionService.getSessionByTourCode(t);
@@ -65,4 +67,30 @@ public class CodeController {
return ResponseEntity.notFound().build();
}
+ @PostMapping
+ public ResponseEntity create(@RequestParam() String code) {
+ TourCode t = null;
+ if (code == null || code.length() < 9) {
+ boolean found = false;
+ for (int i = 0; i < 10; ++i) {
+ code = randomStringUtils.nextAlphanumeric(9);
+ t = tourCodeService.getTourCodeByCode(code);
+ if (t == null) {
+ break;
+ }
+ }
+ if (!found) {
+ return ResponseEntity.internalServerError().body("Couldn't create random code.");
+ }
+ } else {
+ t = tourCodeService.getTourCodeByCode(code);
+ }
+ if (t == null) {
+ t = tourCodeService.addTourCode(code);
+ System.out.println("DEBUG: Created TC " + t.getId());
+ return ResponseEntity.ok(t.getId().toString());
+ }
+ return ResponseEntity.badRequest().body("BAD: " + t.getId());
+ }
+
}
\ No newline at end of file