diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ 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 d5f0072..2d9a20c 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 @@ -14,13 +14,13 @@ public class CodeController { private final TourCodeService tourCodeService; @GetMapping - public String greeting(@RequestParam(defaultValue = "ABCDEFGHI") String code) { + public String test(@RequestParam(defaultValue = "ABCDEFGHI") String code) { TourCode t = tourCodeService.getTourCodeByCode(code); if (t == null) { t = tourCodeService.addTourCode(code); - return "Created TC " + String.valueOf(t.id); + return "Created TC " + t.getId(); } - return "Hello " + t.code + "(" + String.valueOf(t.activated) + ")"; + return "Hello " + t.getCode() + "(" + t.getActivated() + ") " + t.getCreationTimestamp(); } } diff --git a/src/main/java/de/exodus_hn/excalibur_tour/entities/Riddle.java b/src/main/java/de/exodus_hn/excalibur_tour/entities/Riddle.java new file mode 100644 index 0000000..87e1e22 --- /dev/null +++ b/src/main/java/de/exodus_hn/excalibur_tour/entities/Riddle.java @@ -0,0 +1,47 @@ +package de.exodus_hn.excalibur_tour.entities; + +import jakarta.persistence.*; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "riddles") +public class Riddle { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private Integer step; + + @Column(nullable = false) + private Double latitude; + + @Column(nullable = false) + private Double longitude; + + @Column(nullable = false) + private Integer points; + + @Column(nullable = false) + private Integer failPenaltyPoints; + + @Column(nullable = false) + private Integer skipPenaltyPoints; + + @OneToMany(mappedBy = "riddle", cascade = CascadeType.ALL, orphanRemoval = true) + @Builder.Default + private List hints = new ArrayList<>(); + +} diff --git a/src/main/java/de/exodus_hn/excalibur_tour/entities/RiddleHint.java b/src/main/java/de/exodus_hn/excalibur_tour/entities/RiddleHint.java new file mode 100644 index 0000000..f80ba26 --- /dev/null +++ b/src/main/java/de/exodus_hn/excalibur_tour/entities/RiddleHint.java @@ -0,0 +1,29 @@ +package de.exodus_hn.excalibur_tour.entities; + +import jakarta.persistence.*; +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "riddle_hints") +public class RiddleHint { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String hint; + + @Column(nullable = false) + private Integer penaltyPoints; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "riddle_id", nullable = false) + private Riddle riddle; + +} diff --git a/src/main/java/de/exodus_hn/excalibur_tour/entities/TourCode.java b/src/main/java/de/exodus_hn/excalibur_tour/entities/TourCode.java index a536a87..00cfa7b 100644 --- a/src/main/java/de/exodus_hn/excalibur_tour/entities/TourCode.java +++ b/src/main/java/de/exodus_hn/excalibur_tour/entities/TourCode.java @@ -13,15 +13,15 @@ import java.time.LocalDateTime; @AllArgsConstructor @Builder @Entity -@Table(name = "TourCodes") +@Table(name = "tour_codes") public class TourCode { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - public Long id; + private Long id; @Column(nullable = false, unique = true) - public String code; + private String code; @Column(nullable = false) private LocalDateTime creationTimestamp; @@ -34,7 +34,10 @@ public class TourCode { @Builder.Default @Column(nullable = false) - public Boolean activated = true; + private Boolean activated = true; + + @OneToOne(mappedBy = "tourCode", cascade = CascadeType.ALL, orphanRemoval = false) + private TourSession tourSession; public TourCode(String code) { this.code = code; diff --git a/src/main/java/de/exodus_hn/excalibur_tour/entities/TourSession.java b/src/main/java/de/exodus_hn/excalibur_tour/entities/TourSession.java new file mode 100644 index 0000000..3f1164d --- /dev/null +++ b/src/main/java/de/exodus_hn/excalibur_tour/entities/TourSession.java @@ -0,0 +1,44 @@ +package de.exodus_hn.excalibur_tour.entities; + +import com.fasterxml.jackson.databind.JsonNode; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +//@Builder +@Entity +@Table(name = "tour_sessions") +public class TourSession { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "tour_code_id") + private TourCode tourCode; + + @Lob + @Column(name = "data", columnDefinition = "text") + private String data; + + + /*@JdbcTypeCode(SqlTypes.JSON) + @Column(name = "data", columnDefinition = "jsonb") + private JsonNode data;*/ + + /*@JdbcTypeCode(SqlTypes.JSON) + @Column(name = "players", columnDefinition = "jsonb") + @Builder.Default + private List players = new ArrayList<>(); + + @Column(nullable = false) + private Integer points;*/ +}