Skip to content

Commit

Permalink
VKT(Backend:Frontend): Interact with contact requests and enrollment …
Browse files Browse the repository at this point in the history
…appointments through examiner APIs [deploy]
  • Loading branch information
pkoivisto committed Nov 18, 2024
1 parent 6d2e2de commit 1c97216
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_PDF_VALUE;

import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentMoveDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentStatusChangeDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentUpdateDTO;
import fi.oph.vkt.api.dto.clerk.ClerkPaymentLinkDTO;
import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO;
import fi.oph.vkt.model.FeatureFlag;
import fi.oph.vkt.service.ClerkEnrollmentService;
import fi.oph.vkt.service.FeatureFlagService;
Expand Down Expand Up @@ -78,26 +75,6 @@ public ClerkEnrollmentDTO move(@RequestBody @Valid final ClerkEnrollmentMoveDTO
return clerkEnrollmentService.move(dto);
}

@GetMapping(path = "/contact/{enrollmentContactId:\\d+}", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment contact request")
public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(@PathVariable final long enrollmentContactId) {
return clerkEnrollmentService.getEnrollmentContactRequest(enrollmentContactId);
}

@PostMapping(path = "/contact/{enrollmentContactId:\\d+}/convertToAppointment", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Convert enrollment contact request to enrollment appointment")
public ExaminerEnrollmentAppointmentDTO enrollmentContactRequestToAppointment(
@PathVariable final long enrollmentContactId
) {
return clerkEnrollmentService.convertToAppointment(enrollmentContactId);
}

@GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment")
public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(@PathVariable final long enrollmentAppointmentId) {
return clerkEnrollmentService.getEnrollmentAppointment(enrollmentAppointmentId);
}

@GetMapping(path = "/attachment", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Download enrollment attachment")
public void attachmentRedirect(final HttpServletResponse response, @RequestParam final String key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fi.oph.vkt.api.examiner;

import static org.springframework.http.MediaType.ALL_VALUE;

import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO;
import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentUpdateDTO;
Expand All @@ -22,23 +25,56 @@ public class ExaminerEnrollmentController {
@PutMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}")
@Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment")
public ExaminerEnrollmentAppointmentDTO updateEnrollmentAppointment(
@PathVariable String oid,
@PathVariable Long enrollmentAppointmentId,
@RequestBody @Valid final ExaminerEnrollmentAppointmentUpdateDTO dto
) {
return examinerEnrollmentService.updateAppointment(dto);
return examinerEnrollmentService.updateAppointment(oid, enrollmentAppointmentId, dto);
}

@GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades")
@Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment")
public ExaminerEnrollmentGradesDTO getEnrollmentAppointmentGrades(@PathVariable final long enrollmentAppointmentId) {
return examinerEnrollmentService.getAppointmentGrades(enrollmentAppointmentId);
@GetMapping(path = "/contact/{enrollmentContactId:\\d+}", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment contact request")
public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(
@PathVariable String oid,
@PathVariable final long enrollmentContactId
) {
return examinerEnrollmentService.getEnrollmentContactRequest(oid, enrollmentContactId);
}

@PostMapping(path = "/contact/{enrollmentContactId:\\d+}/convertToAppointment", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Convert enrollment contact request to enrollment appointment")
public ExaminerEnrollmentAppointmentDTO enrollmentContactRequestToAppointment(
@PathVariable String oid,
@PathVariable final long enrollmentContactId
) {
return examinerEnrollmentService.convertToAppointment(oid, enrollmentContactId);
}

@GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}", consumes = ALL_VALUE)
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment")
public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(
@PathVariable String oid,
@PathVariable final long enrollmentAppointmentId
) {
return examinerEnrollmentService.getEnrollmentAppointment(oid, enrollmentAppointmentId);
}

@PutMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades")
@Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment")
@Operation(tags = TAG_ENROLLMENT, summary = "Update enrollment appointment grades")
public ExaminerEnrollmentGradesDTO upsertEnrollmentAppointmentGrades(
@PathVariable String oid,
@RequestBody @Valid final ExaminerEnrollmentGradesDTO dto,
@PathVariable final long enrollmentAppointmentId
) {
return examinerEnrollmentService.upsertAppointmentGrades(enrollmentAppointmentId, dto);
return examinerEnrollmentService.upsertAppointmentGrades(oid, enrollmentAppointmentId, dto);
}

@GetMapping(path = "/appointment/{enrollmentAppointmentId:\\d+}/grades")
@Operation(tags = TAG_ENROLLMENT, summary = "Get enrollment appointment grades")
public ExaminerEnrollmentGradesDTO getEnrollmentAppointmentGrades(
@PathVariable String oid,
@PathVariable final long enrollmentAppointmentId
) {
return examinerEnrollmentService.getAppointmentGrades(oid, enrollmentAppointmentId);
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package fi.oph.vkt.service;

import fi.oph.vkt.api.dto.EnrollmentGradeDTO;
import fi.oph.vkt.api.dto.FreeEnrollmentDetails;
import fi.oph.vkt.api.dto.PublicEducationDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentMoveDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentStatusChangeDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentUpdateDTO;
import fi.oph.vkt.api.dto.clerk.ClerkPaymentLinkDTO;
import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO;
import fi.oph.vkt.audit.AuditService;
import fi.oph.vkt.audit.VktOperation;
import fi.oph.vkt.audit.dto.ClerkEnrollmentAuditDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.EnrollmentGrade;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.FreeEnrollment;
import fi.oph.vkt.model.Payment;
import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentGradeType;
import fi.oph.vkt.model.type.EnrollmentStatus;
import fi.oph.vkt.model.type.FreeEnrollmentSource;
import fi.oph.vkt.model.type.PaymentStatus;
import fi.oph.vkt.repository.EnrollmentAppointmentRepository;
import fi.oph.vkt.repository.EnrollmentGradesRepository;
import fi.oph.vkt.repository.EnrollmentRepository;
import fi.oph.vkt.repository.ExamEventRepository;
import fi.oph.vkt.repository.FreeEnrollmentRepository;
Expand All @@ -40,7 +30,6 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -56,8 +45,6 @@ public class ClerkEnrollmentService extends AbstractEnrollmentService {
private static final Logger LOG = LoggerFactory.getLogger(ClerkEnrollmentService.class);

private final EnrollmentRepository enrollmentRepository;
private final EnrollmentAppointmentRepository enrollmentAppointmentRepository;
private final EnrollmentGradesRepository enrollmentGradesRepository;
private final ExamEventRepository examEventRepository;
private final PaymentRepository paymentRepository;
private final AuditService auditService;
Expand Down Expand Up @@ -232,41 +219,4 @@ public void getAndSaveKoskiEducationDetailsForEnrollment(final long enrollmentId
}
koskiService.saveEducationsForEnrollment(freeEnrollment, enrollment.getExamEvent().getId(), educationDTOs);
}

@Transactional(readOnly = true)
public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(final long enrollmentContactId) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentContactId
);

return ClerkEnrollmentUtil.createClerkEnrollmentContactDTO(enrollmentAppointment);
}

@Transactional
public ExaminerEnrollmentAppointmentDTO convertToAppointment(final long enrollmentContactId) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentContactId
);
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

enrollmentAppointment.setStatus(EnrollmentAppointmentStatus.WAITING_AUTHENTICATION);

if (enrollmentAppointment.getAuthHash() == null) {
enrollmentAppointment.setAuthHash(uuidSource.getRandomNonce());
}

enrollmentAppointmentRepository.flush();

return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI);
}

@Transactional(readOnly = true)
public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(final long enrollmentAppointmentId) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentAppointmentId
);
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package fi.oph.vkt.service;

import fi.oph.vkt.api.dto.EnrollmentGradeDTO;
import fi.oph.vkt.api.dto.clerk.ClerkEnrollmentContactRequestDTO;
import fi.oph.vkt.api.dto.clerk.ExaminerEnrollmentGradesDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentDTO;
import fi.oph.vkt.api.dto.examiner.ExaminerEnrollmentAppointmentUpdateDTO;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.EnrollmentGrade;
import fi.oph.vkt.model.ExaminerExamEvent;
import fi.oph.vkt.model.type.EnrollmentAppointmentStatus;
import fi.oph.vkt.model.type.EnrollmentGradeType;
import fi.oph.vkt.repository.EnrollmentAppointmentRepository;
import fi.oph.vkt.repository.EnrollmentGradesRepository;
import fi.oph.vkt.repository.ExaminerExamEventRepository;
import fi.oph.vkt.repository.ExaminerRepository;
import fi.oph.vkt.util.ClerkEnrollmentUtil;
import fi.oph.vkt.util.UUIDSource;
import fi.oph.vkt.util.exception.APIException;
import fi.oph.vkt.util.exception.APIExceptionType;
import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
Expand All @@ -27,10 +32,25 @@ public class ExaminerEnrollmentService extends AbstractEnrollmentService {
private final EnrollmentGradesRepository enrollmentGradesRepository;
private final ExaminerExamEventRepository examinerExamEventRepository;
private final Environment environment;
private final UUIDSource uuidSource;

private static void checkExaminerOid(EnrollmentAppointment enrollmentAppointment, String oid) {
if (!enrollmentAppointment.getExaminer().getOid().equals(oid)) {
throw new APIException(APIExceptionType.EXAMINER_ENROLLMENT_OID_MISMATCH);
}
}

@Transactional
public ExaminerEnrollmentAppointmentDTO updateAppointment(final ExaminerEnrollmentAppointmentUpdateDTO dto) {
public ExaminerEnrollmentAppointmentDTO updateAppointment(
final String oid,
final Long id,
final ExaminerEnrollmentAppointmentUpdateDTO dto
) {
if (!Objects.equals(id, dto.id())) {
throw new APIException(APIExceptionType.EXAMINER_APPOINTMENT_ID_MISMATCH);
}
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(dto.id());
checkExaminerOid(enrollmentAppointment, oid);
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

enrollmentAppointment.assertVersion(dto.version());
Expand All @@ -47,25 +67,78 @@ public ExaminerEnrollmentAppointmentDTO updateAppointment(final ExaminerEnrollme
}

@Transactional(readOnly = true)
public ExaminerEnrollmentGradesDTO getAppointmentGrades(final long enrollmentAppointmentId) {
public ClerkEnrollmentContactRequestDTO getEnrollmentContactRequest(
final String oid,
final long enrollmentContactId
) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentContactId
);
checkExaminerOid(enrollmentAppointment, oid);

return ClerkEnrollmentUtil.createClerkEnrollmentContactDTO(enrollmentAppointment);
}

@Transactional
public ExaminerEnrollmentAppointmentDTO convertToAppointment(final String oid, final long enrollmentContactId) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentContactId
);
checkExaminerOid(enrollmentAppointment, oid);

final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

enrollmentAppointment.setStatus(EnrollmentAppointmentStatus.WAITING_AUTHENTICATION);

if (enrollmentAppointment.getAuthHash() == null) {
enrollmentAppointment.setAuthHash(uuidSource.getRandomNonce());
}

enrollmentAppointmentRepository.flush();

return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI);
}

@Transactional(readOnly = true)
public ExaminerEnrollmentGradesDTO getAppointmentGrades(final String oid, final long enrollmentAppointmentId) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentAppointmentId
);
checkExaminerOid(enrollmentAppointment, oid);
final Optional<EnrollmentGrade> enrollmentGradeOptional = enrollmentGradesRepository.findByEnrollmentAppointment(
enrollmentAppointment
);

return enrollmentGradeOptional.map(this::createGradesDTO).orElse(null);
}

@Transactional(readOnly = true)
public ExaminerEnrollmentAppointmentDTO getEnrollmentAppointment(
final String oid,
final long enrollmentAppointmentId
) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentAppointmentId
);

checkExaminerOid(enrollmentAppointment, oid);

final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api");

return ClerkEnrollmentUtil.createClerkEnrollmentAppointmentDTO(enrollmentAppointment, baseUrlAPI);
}

@Transactional
public ExaminerEnrollmentGradesDTO upsertAppointmentGrades(
final String oid,
final long enrollmentAppointmentId,
final ExaminerEnrollmentGradesDTO dto
) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
enrollmentAppointmentId
);
checkExaminerOid(enrollmentAppointment, oid);

final Optional<EnrollmentGrade> enrollmentGradeOptional = enrollmentGradesRepository.findByEnrollmentAppointment(
enrollmentAppointment
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public enum APIExceptionType {
EXAMINER_NOT_FOUND,
EXAMINER_EXAM_EVENT_NOT_FOUND,
EXAMINER_MUNICIPALITY_MISMATCH,
EXAMINER_EXAM_EVENT_EXAMINER_MISMATCH;
EXAMINER_EXAM_EVENT_EXAMINER_MISMATCH,
EXAMINER_ENROLLMENT_OID_MISMATCH,
EXAMINER_APPOINTMENT_ID_MISMATCH;

public String getCode() {
final StringBuilder codeBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class ClerkEnrollmentServiceTest {
@Resource
private EnrollmentRepository enrollmentRepository;

@Resource
private EnrollmentAppointmentRepository enrollmentAppointmentRepository;

@Resource
private EnrollmentGradesRepository enrollmentGradesRepository;

@Resource
private FreeEnrollmentRepository freeEnrollmentRepository;

Expand Down Expand Up @@ -86,8 +80,6 @@ public void setup() {
clerkEnrollmentService =
new ClerkEnrollmentService(
enrollmentRepository,
enrollmentAppointmentRepository,
enrollmentGradesRepository,
examEventRepository,
paymentRepository,
auditService,
Expand Down
5 changes: 2 additions & 3 deletions frontend/packages/vkt/src/enums/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export enum APIEndpoints {
ClerkUser = '/vkt/api/v1/clerk/user',
PublicUser = '/vkt/api/v1/auth/info',
ClerkEnrollment = '/vkt/api/v1/clerk/enrollment',
ClerkEnrollmentContactRequest = '/vkt/api/v1/clerk/enrollment/contact',
ClerkEnrollmentAppointment = '/vkt/api/v1/clerk/enrollment/appointment',
ExaminerEnrollmentAppointment = '/vkt/api/v1/tv/:oid/enrollment/appointment',
ClerkPayment = '/vkt/api/v1/clerk/payment',
FeatureFlags = '/vkt/api/v1/featureFlags',
UploadPostPolicy = '/vkt/api/v1/uploadPostPolicy/:examEventId',
Expand All @@ -25,6 +22,8 @@ export enum APIEndpoints {
ExaminerDetails = '/vkt/api/v1/tv/:oid',
ExaminerDetailsInit = '/vkt/api/v1/tv/:oid/init',
ExaminerExamEvent = '/vkt/api/v1/tv/:oid/examEvent',
ExaminerEnrollmentAppointment = '/vkt/api/v1/tv/:oid/enrollment/appointment',
ExaminerEnrollmentContactRequest = '/vkt/api/v1/tv/:oid/enrollment/contact',
}

/**
Expand Down
Loading

0 comments on commit 1c97216

Please sign in to comment.