summaryrefslogtreecommitdiff
path: root/src/main/java/com/stileeducation/markr/entity/Test.java
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-07-25 20:36:11 +1000
committerSzymon Szukalski <szymon@skas.io>2024-07-25 20:36:11 +1000
commitaa9bdd514ab90d0da0391b879255a22c29450e9a (patch)
tree9ddd1de0ab7e376ead06f55bdb32a6190d3647d5 /src/main/java/com/stileeducation/markr/entity/Test.java
parentec81d98e90f9fdb4dd12138a365fbbbb3a8efa5f (diff)
Validate import payload and return create/update stats
- Add validation to /import payload - Move import logic to service bean - Track whether entities have been created or update - Report number of created and updated entities as return value for the import endpoint - Add some test coverage to exercise the validators
Diffstat (limited to 'src/main/java/com/stileeducation/markr/entity/Test.java')
-rw-r--r--src/main/java/com/stileeducation/markr/entity/Test.java166
1 files changed, 96 insertions, 70 deletions
diff --git a/src/main/java/com/stileeducation/markr/entity/Test.java b/src/main/java/com/stileeducation/markr/entity/Test.java
index 615d0e1..ff9088e 100644
--- a/src/main/java/com/stileeducation/markr/entity/Test.java
+++ b/src/main/java/com/stileeducation/markr/entity/Test.java
@@ -10,74 +10,100 @@ import java.util.Set;
@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 +
- '}';
- }
+ @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<>();
+
+ @Transient
+ private boolean created = false;
+
+ @Transient
+ private boolean updated = false;
+
+ 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;
+ }
+
+ public boolean isCreated() {
+ return created;
+ }
+
+ public void setCreated(boolean created) {
+ this.created = created;
+ }
+
+ public boolean isUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(boolean updated) {
+ this.updated = updated;
+ }
+
+ @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) &&
+ Objects.equals(created, test.created) &&
+ Objects.equals(updated, test.updated);
+ }
+
+ @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 +
+ ", created=" + created +
+ ", updated=" + updated +
+ '}';
+ }
}