small prod changes

This commit is contained in:
LionTion committed 2026-10-16 04:29:04 +02:00
1 parent 154cf7ce17
commit fc77c7d8aa
3 files changed
+33 -9

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@
</parent> </parent>
<groupId>de.exodus-hn</groupId> <groupId>de.exodus-hn</groupId>
<artifactId>excalibur-tour</artifactId> <artifactId>excalibur-tour</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.1.0</version>
<name/> <name/>
<description/> <description/>
<url/> <url/>
@@ -25,10 +25,6 @@ public class TourCodeHandshakeInterceptor implements HandshakeInterceptor {
String tourCode = servletRequest.getServletRequest().getParameter("tourCode"); String tourCode = servletRequest.getServletRequest().getParameter("tourCode");
// Prüfen, ob der TourCode existiert und gültig ist // 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) { if (tourCode != null && tourCodeService.getTourCodeByCode(tourCode) != null) {
// TourCode in den Session-Attributen für spätere Autorisierungen hinterlegen // TourCode in den Session-Attributen für spätere Autorisierungen hinterlegen
attributes.put("tourCode", tourCode); attributes.put("tourCode", tourCode);
@@ -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.TourCodeService;
import de.exodus_hn.excalibur_tour.services.TourSessionService; import de.exodus_hn.excalibur_tour.services.TourSessionService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -26,6 +27,7 @@ public class CodeController {
private final TourSessionService tourSessionService; private final TourSessionService tourSessionService;
private final RiddleService riddleService; private final RiddleService riddleService;
private final RiddleMapper riddleMapper; private final RiddleMapper riddleMapper;
private final RandomStringUtils randomStringUtils = RandomStringUtils.secure();
@GetMapping @GetMapping
public ResponseEntity<GetSessionAndAllRiddleData> check(@RequestParam() String code) { public ResponseEntity<GetSessionAndAllRiddleData> check(@RequestParam() String code) {
@@ -34,8 +36,8 @@ public class CodeController {
} }
TourCode t = tourCodeService.getTourCodeByCode(code); TourCode t = tourCodeService.getTourCodeByCode(code);
if (t == null) { if (t == null) {
t = tourCodeService.addTourCode(code); /*t = tourCodeService.addTourCode(code);
System.out.println("DEBUG: Created TC " + t.getId()); System.out.println("DEBUG: Created TC " + t.getId());*/
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
LocalDateTime now = Utils.getDateTimeNow(); LocalDateTime now = Utils.getDateTimeNow();
@@ -48,9 +50,9 @@ public class CodeController {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
LocalDateTime heartbeat = t.getLastHeartbeatTimestamp(); 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(); return ResponseEntity.notFound().build();
}*/ }
t.setLastHeartbeatTimestamp(now); t.setLastHeartbeatTimestamp(now);
tourCodeService.updateCode(t); tourCodeService.updateCode(t);
TourSession tourSession = tourSessionService.getSessionByTourCode(t); TourSession tourSession = tourSessionService.getSessionByTourCode(t);
@@ -65,4 +67,30 @@ public class CodeController {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
@PostMapping
public ResponseEntity<String> 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());
}
} }