summaryrefslogtreecommitdiff
path: root/src/main/java/com/stileeducation/markr/entity/Test.java
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-07-23 23:19:45 +1000
committerSzymon Szukalski <szymon@skas.io>2024-07-23 23:19:45 +1000
commitfa34f76ad8ebccb96012b45a4207532846cfa03f (patch)
treee11e7a675d8d23a4921be505cec16b735abbd23d /src/main/java/com/stileeducation/markr/entity/Test.java
parent6964e0bc8578abcbdf7e49ffa36c49197df67787 (diff)
Define JPA entities and repositories and H2 DB
Diffstat (limited to 'src/main/java/com/stileeducation/markr/entity/Test.java')
-rw-r--r--src/main/java/com/stileeducation/markr/entity/Test.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/com/stileeducation/markr/entity/Test.java b/src/main/java/com/stileeducation/markr/entity/Test.java
new file mode 100644
index 0000000..3729e1b
--- /dev/null
+++ b/src/main/java/com/stileeducation/markr/entity/Test.java
@@ -0,0 +1,80 @@
+package com.stileeducation.markr.entity;
+
+import jakarta.persistence.*;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+@Entity
+@Table(name = "tests")
+public class Test {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @Column(name = "test_id", nullable = false, unique = true)
+ private String testId;
+
+ @Column(name = "marks_available", nullable = false)
+ private Integer marksAvailable;
+
+ @OneToMany(mappedBy = "test", cascade = CascadeType.ALL, orphanRemoval = true)
+ private Set<TestResult> testResults = new HashSet<>();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTestId() {
+ return testId;
+ }
+
+ public void setTestId(String testId) {
+ this.testId = testId;
+ }
+
+ public Integer getMarksAvailable() {
+ return marksAvailable;
+ }
+
+ public void setMarksAvailable(Integer marksAvailable) {
+ this.marksAvailable = marksAvailable;
+ }
+
+ public Set<TestResult> getTestResults() {
+ return testResults;
+ }
+
+ public void setTestResults(Set<TestResult> testResults) {
+ this.testResults = testResults;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Test test = (Test) o;
+ return Objects.equals(id, test.id) && Objects.equals(testId, test.testId) && Objects.equals(marksAvailable, test.marksAvailable) && Objects.equals(testResults, test.testResults);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, testId, marksAvailable, testResults);
+ }
+
+ @Override
+ public String toString() {
+ return "Test{" +
+ "id=" + id +
+ ", testId='" + testId + '\'' +
+ ", marksAvailable=" + marksAvailable +
+ ", testResults=" + testResults +
+ '}';
+ }
+}