Skip to content

Commit

Permalink
VKT(Backend): Enrollment contact request backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Oct 31, 2024
1 parent bb20fb4 commit 0f7fc10
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.springframework.http.MediaType.APPLICATION_PDF_VALUE;

import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentAppointmentDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentAppointmentUpdateDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentMoveDTO;
Expand Down Expand Up @@ -85,7 +86,9 @@ public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(@PathVariabl

@PutMapping(path = "/contact/{enrollmentContactId:\\d+}/convertToAppointment")
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment contact request")
public long enrollmentContactRequestToAppointment(@PathVariable final long enrollmentContactId) {
public ClerkEnrollmentAppointmentDTO enrollmentContactRequestToAppointment(
@PathVariable final long enrollmentContactId
) {
return clerkEnrollmentService.convertToAppointment(enrollmentContactId);
}

Expand All @@ -97,8 +100,10 @@ public ClerkEnrollmentAppointmentDTO getEnrollmentAppointment(@PathVariable fina

@PutMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}")
@Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment")
public ClerkEnrollmentDTO updateEnrollmentAppointment(@RequestBody @Valid final ClerkEnrollmentUpdateDTO dto) {
return clerkEnrollmentService.update(dto);
public ClerkEnrollmentAppointmentDTO updateEnrollmentAppointment(
@RequestBody @Valid final ClerkEnrollmentAppointmentUpdateDTO dto
) {
return clerkEnrollmentService.updateAppointment(dto);
}

@GetMapping(path = "/attachment", consumes = ALL_VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package fi.oph.vkt.api.dto;

public interface EnrollmentDTOCommonFields {
Boolean oralSkill();
Boolean textualSkill();
Boolean understandingSkill();
Boolean speakingPartialExam();
Boolean speechComprehensionPartialExam();
Boolean writingPartialExam();
Boolean readingComprehensionPartialExam();
public interface EnrollmentDTOCommonFields extends EnrollmentDTOSkillFields {
String previousEnrollment();
Boolean digitalCertificateConsent();
String email();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fi.oph.vkt.api.dto;

public interface EnrollmentDTOSkillFields {
Boolean oralSkill();
Boolean textualSkill();
Boolean understandingSkill();
Boolean speakingPartialExam();
Boolean speechComprehensionPartialExam();
Boolean writingPartialExam();
Boolean readingComprehensionPartialExam();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.oph.vkt.api.dto;

import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -16,7 +17,7 @@ public record PublicEnrollmentAppointmentDTO(
@NonNull @NotNull Boolean speechComprehensionPartialExam,
@NonNull @NotNull Boolean writingPartialExam,
@NonNull @NotNull Boolean readingComprehensionPartialExam,
@NonNull @NotNull EnrollmentStatus status,
@NonNull @NotNull EnrollmentAppointmentStatus status,
String previousEnrollment,
@NonNull @NotNull Boolean digitalCertificateConsent,
@NonNull @NotBlank String email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public record PublicEnrollmentContactCreateDTO(
@Size(max = 255) @NonNull @NotBlank String email,
@Size(max = 255) @NonNull @NotBlank String firstName,
@Size(max = 255) @NonNull @NotBlank String lastName
) {
)
implements EnrollmentDTOSkillFields {
public PublicEnrollmentContactCreateDTO {
previousEnrollment = StringUtil.sanitize(previousEnrollment);
email = StringUtil.sanitize(email);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fi.oph.vkt.api.dto.clerk;

import fi.oph.vkt.api.dto.EnrollmentDTOSkillFields;
import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -20,10 +22,16 @@ public record ClerkEnrollmentAppointmentDTO(
@NonNull @NotNull Boolean speechComprehensionPartialExam,
@NonNull @NotNull Boolean writingPartialExam,
@NonNull @NotNull Boolean readingComprehensionPartialExam,
@NonNull @NotNull EnrollmentStatus status,
@NonNull @NotNull EnrollmentAppointmentStatus status,
String previousEnrollment,
@NonNull @NotBlank String email,
String phoneNumber,
String street,
String postalCode,
String town,
String country,
@NonNull @NotBlank String firstName,
@NonNull @NotBlank String lastName,
@NonNull @NotNull List<ClerkPaymentDTO> payments
) {}
)
implements EnrollmentDTOSkillFields {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fi.oph.vkt.api.dto.clerk;

import fi.oph.vkt.api.dto.EnrollmentDTOSkillFields;
import fi.oph.vkt.model.type.EnrollmentStatus;
import fi.oph.vkt.util.StringUtil;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;

@Builder
public record ClerkEnrollmentAppointmentUpdateDTO(
@NonNull @NotNull Long id,
@NonNull @NotNull Integer version,
@NonNull @NotNull LocalDateTime enrollmentTime,
@NonNull @NotNull Boolean oralSkill,
@NonNull @NotNull Boolean textualSkill,
@NonNull @NotNull Boolean understandingSkill,
@NonNull @NotNull Boolean speakingPartialExam,
@NonNull @NotNull Boolean speechComprehensionPartialExam,
@NonNull @NotNull Boolean writingPartialExam,
@NonNull @NotNull Boolean readingComprehensionPartialExam,
String previousEnrollment,
@NonNull @NotBlank String email,
@NonNull @NotBlank String firstName,
@NonNull @NotBlank String lastName,
String phoneNumber,
@Size(max = 255) String street,
@Size(max = 255) String postalCode,
@Size(max = 255) String town,
@Size(max = 255) String country,
@NonNull @NotNull List<ClerkPaymentDTO> payments
)
implements EnrollmentDTOSkillFields {
public ClerkEnrollmentAppointmentUpdateDTO {
previousEnrollment = StringUtil.sanitize(previousEnrollment);
email = StringUtil.sanitize(email);
phoneNumber = StringUtil.sanitize(phoneNumber);
street = StringUtil.sanitize(street);
postalCode = StringUtil.sanitize(postalCode);
town = StringUtil.sanitize(town);
country = StringUtil.sanitize(country);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.oph.vkt.api.dto.clerk;

import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -19,7 +20,7 @@ public record ClerkEnrollmentContactRequestDTO(
@NonNull @NotNull Boolean speechComprehensionPartialExam,
@NonNull @NotNull Boolean writingPartialExam,
@NonNull @NotNull Boolean readingComprehensionPartialExam,
@NonNull @NotNull EnrollmentStatus status,
@NonNull @NotNull EnrollmentAppointmentStatus status,
String previousEnrollment,
@NonNull @NotBlank String email,
@NonNull @NotBlank String firstName,
Expand Down
23 changes: 1 addition & 22 deletions backend/vkt/src/main/java/fi/oph/vkt/model/Enrollment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,13 @@
@Setter
@Entity
@Table(name = "enrollment")
public class Enrollment extends BaseEntity {
public class Enrollment extends EnrollmentCommon {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "enrollment_id", nullable = false)
private long id;

@Column(name = "skill_oral", nullable = false)
private boolean oralSkill;

@Column(name = "skill_textual", nullable = false)
private boolean textualSkill;

@Column(name = "skill_understanding", nullable = false)
private boolean understandingSkill;

@Column(name = "partial_exam_speaking", nullable = false)
private boolean speakingPartialExam;

@Column(name = "partial_exam_speech_comprehension", nullable = false)
private boolean speechComprehensionPartialExam;

@Column(name = "partial_exam_writing", nullable = false)
private boolean writingPartialExam;

@Column(name = "partial_exam_reading_comprehension", nullable = false)
private boolean readingComprehensionPartialExam;

@Column(name = "status", nullable = false)
@Enumerated(value = EnumType.STRING)
private EnrollmentStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.oph.vkt.model;

import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -25,37 +26,16 @@
@Setter
@Entity
@Table(name = "enrollment_appointment")
public class EnrollmentAppointment extends BaseEntity {
public class EnrollmentAppointment extends EnrollmentCommon {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "enrollment_appointment_id", nullable = false)
private long id;

@Column(name = "skill_oral")
private boolean oralSkill;

@Column(name = "skill_textual")
private boolean textualSkill;

@Column(name = "skill_understanding")
private boolean understandingSkill;

@Column(name = "partial_exam_speaking")
private boolean speakingPartialExam;

@Column(name = "partial_exam_speech_comprehension")
private boolean speechComprehensionPartialExam;

@Column(name = "partial_exam_writing")
private boolean writingPartialExam;

@Column(name = "partial_exam_reading_comprehension")
private boolean readingComprehensionPartialExam;

@Column(name = "status", nullable = false)
@Enumerated(value = EnumType.STRING)
private EnrollmentStatus status;
private EnrollmentAppointmentStatus status;

@Column(name = "digital_certificate_consent")
private boolean digitalCertificateConsent;
Expand Down
33 changes: 33 additions & 0 deletions backend/vkt/src/main/java/fi/oph/vkt/model/EnrollmentCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fi.oph.vkt.model;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@MappedSuperclass
public class EnrollmentCommon extends BaseEntity {

@Column(name = "skill_oral")
private boolean oralSkill;

@Column(name = "skill_textual")
private boolean textualSkill;

@Column(name = "skill_understanding")
private boolean understandingSkill;

@Column(name = "partial_exam_speaking")
private boolean speakingPartialExam;

@Column(name = "partial_exam_speech_comprehension")
private boolean speechComprehensionPartialExam;

@Column(name = "partial_exam_writing")
private boolean writingPartialExam;

@Column(name = "partial_exam_reading_comprehension")
private boolean readingComprehensionPartialExam;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fi.oph.vkt.model.type;

public enum EnrollmentAppointmentStatus {
COMPLETED,
AWAITING_PAYMENT,
CANCELED,
EXPECTING_PAYMENT,
WAITING_AUTHENTICATION,
CANCELED_PAYMENT,
CONTACT_CREATED,
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
package fi.oph.vkt.service;

import fi.oph.vkt.api.dto.EnrollmentDTOCommonFields;
import fi.oph.vkt.api.dto.EnrollmentDTOSkillFields;
import fi.oph.vkt.api.dto.PublicEnrollmentContactCreateDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentAppointmentUpdateDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.EnrollmentCommon;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.Person;
import fi.oph.vkt.repository.EnrollmentRepository;
import java.util.Optional;

public abstract class AbstractEnrollmentService {

protected void copyDtoFieldsToEnrollment(
final EnrollmentAppointment enrollment,
final PublicEnrollmentContactCreateDTO dto
) {
protected void copyDtoSkillFieldsToEnrollment(final EnrollmentCommon enrollment, final EnrollmentDTOSkillFields dto) {
enrollment.setOralSkill(dto.oralSkill());
enrollment.setTextualSkill(dto.textualSkill());
enrollment.setUnderstandingSkill(dto.understandingSkill());
enrollment.setSpeakingPartialExam(dto.speakingPartialExam());
enrollment.setSpeechComprehensionPartialExam(dto.speechComprehensionPartialExam());
enrollment.setWritingPartialExam(dto.writingPartialExam());
enrollment.setReadingComprehensionPartialExam(dto.readingComprehensionPartialExam());
}

protected void copyDtoFieldsToEnrollment(
final EnrollmentAppointment enrollment,
final ClerkEnrollmentAppointmentUpdateDTO dto
) {
copyDtoSkillFieldsToEnrollment(enrollment, dto);
enrollment.setEmail(dto.email());
}

protected void copyDtoFieldsToEnrollment(
final EnrollmentAppointment enrollment,
final PublicEnrollmentContactCreateDTO dto
) {
copyDtoSkillFieldsToEnrollment(enrollment, dto);
enrollment.setEmail(dto.email());
}

protected void copyDtoFieldsToEnrollment(final Enrollment enrollment, final EnrollmentDTOCommonFields dto) {
enrollment.setOralSkill(dto.oralSkill());
enrollment.setTextualSkill(dto.textualSkill());
enrollment.setUnderstandingSkill(dto.understandingSkill());
enrollment.setSpeakingPartialExam(dto.speakingPartialExam());
enrollment.setSpeechComprehensionPartialExam(dto.speechComprehensionPartialExam());
enrollment.setWritingPartialExam(dto.writingPartialExam());
enrollment.setReadingComprehensionPartialExam(dto.readingComprehensionPartialExam());
copyDtoSkillFieldsToEnrollment(enrollment, dto);
enrollment.setPreviousEnrollment(dto.previousEnrollment());
enrollment.setDigitalCertificateConsent(dto.digitalCertificateConsent());
enrollment.setEmail(dto.email());
Expand Down
Loading

0 comments on commit 0f7fc10

Please sign in to comment.