From d876291d2f76e73a70ebd8eb0f0ccb1aa1d39e7b Mon Sep 17 00:00:00 2001 From: Pyry Koivisto Date: Thu, 7 Nov 2024 21:08:25 +0200 Subject: [PATCH] VKT(Backend): Create new ExaminerExamEvent table for exams of good and satisfactory level. Drop references to examiners from ExamEvent table. --- .../main/java/fi/oph/vkt/model/ExamEvent.java | 16 +--- .../fi/oph/vkt/model/ExamEventCommon.java | 26 ++++++ .../main/java/fi/oph/vkt/model/Examiner.java | 2 +- .../fi/oph/vkt/model/ExaminerExamEvent.java | 40 +++++++++ .../vkt/service/PublicExaminerService.java | 11 ++- .../db/changelog/db.changelog-1.0.xml | 81 ++++++++++--------- 6 files changed, 118 insertions(+), 58 deletions(-) create mode 100644 backend/vkt/src/main/java/fi/oph/vkt/model/ExamEventCommon.java create mode 100644 backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerExamEvent.java diff --git a/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEvent.java b/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEvent.java index 870a8dd65..11a15f77b 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEvent.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEvent.java @@ -14,33 +14,23 @@ @Setter @Entity @Table(name = "exam_event") -public class ExamEvent extends BaseEntity { +public class ExamEvent extends ExamEventCommon { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "exam_event_id", nullable = false) private long id; - @Column(name = "language", nullable = false) - @Enumerated(value = EnumType.STRING) - private ExamLanguage language; - @Column(name = "level", nullable = false) @Enumerated(value = EnumType.STRING) private ExamLevel level; - @Column(name = "date", nullable = false) - private LocalDate date; - @Column(name = "registration_opens", nullable = false) private LocalDateTime registrationOpens; @Column(name = "registration_closes", nullable = false) private LocalDateTime registrationCloses; - @Column(name = "is_hidden", nullable = false) - private boolean isHidden; - @Column(name = "max_participants", nullable = false) private long maxParticipants; @@ -49,8 +39,4 @@ public class ExamEvent extends BaseEntity { @OneToMany(mappedBy = "examEvent") private List reservations = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "examiner_id", referencedColumnName = "examiner_id") - private Examiner examiner; } diff --git a/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEventCommon.java b/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEventCommon.java new file mode 100644 index 000000000..f4d439368 --- /dev/null +++ b/backend/vkt/src/main/java/fi/oph/vkt/model/ExamEventCommon.java @@ -0,0 +1,26 @@ +package fi.oph.vkt.model; + +import fi.oph.vkt.model.type.ExamLanguage; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.MappedSuperclass; +import java.time.LocalDate; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@MappedSuperclass +public class ExamEventCommon extends BaseEntity { + + @Column(name = "language", nullable = false) + @Enumerated(value = EnumType.STRING) + private ExamLanguage language; + + @Column(name = "date", nullable = false) + private LocalDate date; + + @Column(name = "is_hidden", nullable = false) + private boolean isHidden; +} diff --git a/backend/vkt/src/main/java/fi/oph/vkt/model/Examiner.java b/backend/vkt/src/main/java/fi/oph/vkt/model/Examiner.java index 1649bb93c..b83a613a1 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/model/Examiner.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/model/Examiner.java @@ -46,7 +46,7 @@ public class Examiner extends BaseEntity { private boolean examLanguageSwedish; @OneToMany(mappedBy = "examiner") - private List examEvents = new ArrayList<>(); + private List examEvents = new ArrayList<>(); @Column(name = "is_public", nullable = false) private boolean isPublic; diff --git a/backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerExamEvent.java b/backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerExamEvent.java new file mode 100644 index 000000000..c1fb73c2f --- /dev/null +++ b/backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerExamEvent.java @@ -0,0 +1,40 @@ +package fi.oph.vkt.model; + +import jakarta.persistence.*; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Entity +@Table(name = "examiner_exam_event") +public class ExaminerExamEvent extends ExamEventCommon { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "examiner_exam_event_id", nullable = false) + private long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "examiner_id", referencedColumnName = "examiner_id") + private Examiner examiner; + + @Column(name = "registration_closes") + private LocalDateTime registrationCloses; + + @Column(name = "max_participants") + private Long maxParticipants; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "municipality_id", referencedColumnName = "municipality_id", nullable = false) + private Municipality municipality; + + @Column(name = "location", nullable = false) + private String location; + //@OneToMany(mappedBy = "examinerExamEvent") + //private List enrollments = new ArrayList<>(); + +} diff --git a/backend/vkt/src/main/java/fi/oph/vkt/service/PublicExaminerService.java b/backend/vkt/src/main/java/fi/oph/vkt/service/PublicExaminerService.java index 640d205c1..bb1a70939 100644 --- a/backend/vkt/src/main/java/fi/oph/vkt/service/PublicExaminerService.java +++ b/backend/vkt/src/main/java/fi/oph/vkt/service/PublicExaminerService.java @@ -5,6 +5,7 @@ import fi.oph.vkt.api.dto.PublicMunicipalityDTO; import fi.oph.vkt.model.ExamEvent; import fi.oph.vkt.model.Examiner; +import fi.oph.vkt.model.ExaminerExamEvent; import fi.oph.vkt.model.Municipality; import fi.oph.vkt.model.type.ExamLanguage; import fi.oph.vkt.repository.ExaminerRepository; @@ -25,12 +26,10 @@ private static PublicMunicipalityDTO toPublicMunicipalityDTO(Municipality munici return PublicMunicipalityDTO.builder().fi(municipality.getNameFI()).sv(municipality.getNameSV()).build(); } - private static PublicExaminerExamDateDTO toPublicExaminerExamDateDTO(ExamEvent examEvent) { - return PublicExaminerExamDateDTO - .builder() - .examDate(examEvent.getDate()) - .isFull(examEvent.getMaxParticipants() <= examEvent.getEnrollments().size()) - .build(); + private static PublicExaminerExamDateDTO toPublicExaminerExamDateDTO(ExaminerExamEvent examEvent) { + // TODO If maxParticipants is set, compare it against number of EnrollmentAppointments linked to examEvent + final boolean isFull = examEvent.getMaxParticipants() != null; + return PublicExaminerExamDateDTO.builder().examDate(examEvent.getDate()).isFull(isFull).build(); } private static PublicExaminerDTO toPublicExaminerDTO(Examiner examiner) { diff --git a/backend/vkt/src/main/resources/db/changelog/db.changelog-1.0.xml b/backend/vkt/src/main/resources/db/changelog/db.changelog-1.0.xml index 53fa9a8d7..57ee52ba3 100644 --- a/backend/vkt/src/main/resources/db/changelog/db.changelog-1.0.xml +++ b/backend/vkt/src/main/resources/db/changelog/db.changelog-1.0.xml @@ -1020,47 +1020,11 @@ referencedTableName="municipality" referencedColumnNames="municipality_id"/> - - - - - - - - - - - - - - - - - - - - - - - - @@ -1078,4 +1042,49 @@ referencedTableName="examiner" referencedColumnNames="examiner_id"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +