Skip to content

Commit

Permalink
VKT(Frontend & Backend): enrollment appointment continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Oct 3, 2024
1 parent 1845ba1 commit 146cf07
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ public PublicEnrollmentAppointmentDTO getEnrollmentAppointment(
@PostMapping(path = "/enrollment/appointment/{enrollmentAppointmentId:\\d+}")
@ResponseStatus(HttpStatus.CREATED)
public PublicEnrollmentAppointmentDTO saveEnrollmentAppointment(
@RequestBody @Valid final PublicEnrollmentAppointmentUpdateDTO dto,
@PathVariable final long enrollmentAppointmentId,
final HttpSession session) {
@RequestBody @Valid final PublicEnrollmentAppointmentUpdateDTO dto,
@PathVariable final long enrollmentAppointmentId,
final HttpSession session
) {
final Person person = publicAuthService.getPersonFromSession(session);

if (enrollmentAppointmentId != dto.id()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public record PublicEnrollmentAppointmentUpdateDTO(
String postalCode,
String town,
String country
) {
}
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public enum ExamLevel {
EXCELLENT,
GOOD,
}
44 changes: 34 additions & 10 deletions backend/vkt/src/main/java/fi/oph/vkt/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fi.oph.vkt.model.type.AppLocale;
import fi.oph.vkt.model.type.EnrollmentSkill;
import fi.oph.vkt.model.type.EnrollmentStatus;
import fi.oph.vkt.model.type.ExamLevel;
import fi.oph.vkt.model.type.PaymentStatus;
import fi.oph.vkt.payment.PaymentProvider;
import fi.oph.vkt.payment.paytrail.Customer;
Expand Down Expand Up @@ -47,28 +48,36 @@ public class PaymentService {
private final Environment environment;
private final PublicEnrollmentEmailService publicEnrollmentEmailService;

private Item getItem(final EnrollmentSkill enrollmentSkill, final int unitPrice) {
private Item getItem(final EnrollmentSkill enrollmentSkill, final int unitPrice, final ExamLevel examLevel) {
return Item
.builder()
.units(1)
.unitPrice(unitPrice)
.vatPercentage(PaytrailConfig.VAT)
.productCode(enrollmentSkill.toString())
.productCode(examLevel.toString() + "-" + enrollmentSkill.toString())
.build();
}

private List<Item> getItems(final EnrollmentAppointment enrollmentAppointment) {
final List<Item> itemList = new ArrayList<>();

if (enrollmentAppointment.isTextualSkill()) {
itemList.add(getItem(EnrollmentSkill.TEXTUAL, EnrollmentUtil.getTextualSkillFee(enrollmentAppointment)));
itemList.add(
getItem(EnrollmentSkill.TEXTUAL, EnrollmentUtil.getTextualSkillFee(enrollmentAppointment), ExamLevel.GOOD)
);
}
if (enrollmentAppointment.isOralSkill()) {
itemList.add(getItem(EnrollmentSkill.ORAL, EnrollmentUtil.getOralSkillFee(enrollmentAppointment)));
itemList.add(
getItem(EnrollmentSkill.ORAL, EnrollmentUtil.getOralSkillFee(enrollmentAppointment), ExamLevel.GOOD)
);
}
if (enrollmentAppointment.isUnderstandingSkill()) {
itemList.add(
getItem(EnrollmentSkill.UNDERSTANDING, EnrollmentUtil.getUnderstandingSkillFee(enrollmentAppointment))
getItem(
EnrollmentSkill.UNDERSTANDING,
EnrollmentUtil.getUnderstandingSkillFee(enrollmentAppointment),
ExamLevel.GOOD
)
);
}

Expand All @@ -80,14 +89,26 @@ private List<Item> getItems(final Enrollment enrollment, final FreeEnrollmentDet

if (enrollment.isTextualSkill()) {
itemList.add(
getItem(EnrollmentSkill.TEXTUAL, EnrollmentUtil.getTextualSkillFee(enrollment, freeEnrollmentDetails))
getItem(
EnrollmentSkill.TEXTUAL,
EnrollmentUtil.getTextualSkillFee(enrollment, freeEnrollmentDetails),
ExamLevel.EXCELLENT
)
);
}
if (enrollment.isOralSkill()) {
itemList.add(getItem(EnrollmentSkill.ORAL, EnrollmentUtil.getOralSkillFee(enrollment, freeEnrollmentDetails)));
itemList.add(
getItem(
EnrollmentSkill.ORAL,
EnrollmentUtil.getOralSkillFee(enrollment, freeEnrollmentDetails),
ExamLevel.EXCELLENT
)
);
}
if (enrollment.isUnderstandingSkill()) {
itemList.add(getItem(EnrollmentSkill.UNDERSTANDING, EnrollmentUtil.getUnderstandingSkillFee(enrollment)));
itemList.add(
getItem(EnrollmentSkill.UNDERSTANDING, EnrollmentUtil.getUnderstandingSkillFee(enrollment), ExamLevel.EXCELLENT)
);
}

return itemList;
Expand All @@ -100,7 +121,10 @@ private EnrollmentStatus getPaymentSuccessEnrollmentNextStatus(final Enrollment
return enrollment.enrollmentNeedsApproval() ? EnrollmentStatus.AWAITING_APPROVAL : EnrollmentStatus.COMPLETED;
}

private void setEnrollmentStatus(final EnrollmentAppointment enrollmentAppointment, final PaymentStatus paymentStatus) {
private void setEnrollmentStatus(
final EnrollmentAppointment enrollmentAppointment,
final PaymentStatus paymentStatus
) {
switch (paymentStatus) {
case NEW, PENDING, DELAYED -> {}
case OK -> enrollmentAppointment.setStatus(EnrollmentStatus.COMPLETED);
Expand Down Expand Up @@ -204,7 +228,7 @@ private String getFinalizePaymentRedirectUrl(final Long paymentId, final String
final Payment payment = paymentRepository
.findById(paymentId)
.orElseThrow(() -> new NotFoundException("Payment not found"));

return payment.getEnrollment() != null
? String.format("%s/ilmoittaudu/%d/maksu/%s", baseUrl, payment.getEnrollment().getExamEvent().getId(), state)
: String.format("%s/markkinapaikka/%d/maksu/%s", baseUrl, payment.getEnrollmentAppointment().getId(), state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,11 @@ public PublicEnrollmentAppointmentDTO getEnrollmentAppointment(
}

@Transactional
public PublicEnrollmentAppointmentDTO saveEnrollmentAppointment(final PublicEnrollmentAppointmentUpdateDTO dto, final Person person) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(
dto.id()
);
public PublicEnrollmentAppointmentDTO saveEnrollmentAppointment(
final PublicEnrollmentAppointmentUpdateDTO dto,
final Person person
) {
final EnrollmentAppointment enrollmentAppointment = enrollmentAppointmentRepository.getReferenceById(dto.id());

if (person.getId() != enrollmentAppointment.getPerson().getId()) {
throw new APIException(APIExceptionType.RESERVATION_PERSON_SESSION_MISMATCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import fi.oph.vkt.model.type.AppLocale;
import fi.oph.vkt.model.type.EnrollmentSkill;
import fi.oph.vkt.model.type.EnrollmentStatus;
import fi.oph.vkt.model.type.ExamLevel;
import fi.oph.vkt.model.type.PaymentStatus;
import fi.oph.vkt.payment.paytrail.Customer;
import fi.oph.vkt.payment.paytrail.Item;
import fi.oph.vkt.payment.paytrail.PaytrailPaymentProvider;
import fi.oph.vkt.payment.paytrail.PaytrailResponseDTO;
import fi.oph.vkt.repository.EnrollmentAppointmentRepository;
import fi.oph.vkt.repository.EnrollmentRepository;
import fi.oph.vkt.repository.PaymentRepository;
import fi.oph.vkt.util.exception.APIException;
Expand Down Expand Up @@ -56,6 +58,9 @@ public class PaymentServiceTest {
@Resource
private EnrollmentRepository enrollmentRepository;

@Resource
private EnrollmentAppointmentRepository enrollmentAppointmentRepository;

@Resource
private TestEntityManager entityManager;

Expand Down Expand Up @@ -94,19 +99,32 @@ public void testCreatePaymentWithAllSkills() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
final String redirectUrl = paymentService.createPaymentForEnrollment(enrollment.getId(), person, AppLocale.FI);
final List<Item> items = List.of(
Item.builder().units(1).unitPrice(25700).vatPercentage(0).productCode(EnrollmentSkill.TEXTUAL.toString()).build(),
Item.builder().units(1).unitPrice(25700).vatPercentage(0).productCode(EnrollmentSkill.ORAL.toString()).build(),
Item
.builder()
.units(1)
.unitPrice(25700)
.vatPercentage(0)
.productCode(ExamLevel.EXCELLENT + "-" + EnrollmentSkill.TEXTUAL)
.build(),
Item
.builder()
.units(1)
.unitPrice(25700)
.vatPercentage(0)
.productCode(ExamLevel.EXCELLENT + "-" + EnrollmentSkill.ORAL)
.build(),
Item
.builder()
.units(1)
.unitPrice(0)
.vatPercentage(0)
.productCode(EnrollmentSkill.UNDERSTANDING.toString())
.productCode(ExamLevel.EXCELLENT + "-" + EnrollmentSkill.UNDERSTANDING)
.build()
);
final Customer customer = Customer
Expand Down Expand Up @@ -160,19 +178,26 @@ public void testCreatePaymentWithoutOralSkill() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
final String redirectUrl = paymentService.createPaymentForEnrollment(enrollment.getId(), person, AppLocale.FI);

final List<Item> items = List.of(
Item.builder().units(1).unitPrice(25700).vatPercentage(0).productCode(EnrollmentSkill.TEXTUAL.toString()).build(),
Item
.builder()
.units(1)
.unitPrice(25700)
.vatPercentage(0)
.productCode(ExamLevel.EXCELLENT + "-" + EnrollmentSkill.TEXTUAL)
.build(),
Item
.builder()
.units(1)
.unitPrice(0)
.vatPercentage(0)
.productCode(EnrollmentSkill.UNDERSTANDING.toString())
.productCode(ExamLevel.EXCELLENT + "-" + EnrollmentSkill.UNDERSTANDING)
.build()
);

Expand Down Expand Up @@ -203,6 +228,7 @@ public void testCreatePaymentPassesProperCustomerDataToPaymentProvider() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -237,6 +263,7 @@ public void testCreatePaymentWrongPerson() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand All @@ -259,6 +286,7 @@ public void testCreatePaymentEnrollmentNotFound() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -287,6 +315,7 @@ public void testFinalizePaymentOnSuccess() throws IOException, InterruptedExcept
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -315,6 +344,7 @@ public void testFinalizePaymentOnFailure() throws IOException, InterruptedExcept
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand All @@ -340,6 +370,7 @@ public void testFinalizePaymentValidationFailed() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -368,6 +399,7 @@ public void testFinalizePaymentOnFailureAlreadyPaid() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -396,6 +428,7 @@ public void testFinalizePaymentOnSuccessAlreadyPaid() throws IOException, Interr
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand All @@ -420,6 +453,7 @@ public void testFinalizePaymentAmountMustMatch() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down Expand Up @@ -449,6 +483,7 @@ public void testFinalizePaymentReferenceIdMustMatch() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand All @@ -471,6 +506,7 @@ public void testFinalizePaymentPaymentNotFound() {
paymentProvider,
paymentRepository,
enrollmentRepository,
enrollmentAppointmentRepository,
environment,
publicEnrollmentEmailService
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import fi.oph.vkt.api.dto.PublicExamEventDTO;
import fi.oph.vkt.api.dto.PublicPersonDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.FeatureFlag;
import fi.oph.vkt.model.Person;
import fi.oph.vkt.model.Reservation;
import fi.oph.vkt.model.type.EnrollmentStatus;
import fi.oph.vkt.repository.EnrollmentAppointmentRepository;
import fi.oph.vkt.repository.EnrollmentRepository;
import fi.oph.vkt.repository.ExamEventRepository;
import fi.oph.vkt.repository.FreeEnrollmentRepository;
Expand Down Expand Up @@ -60,6 +62,9 @@ public class PublicEnrollmentServiceTest {
@Resource
private EnrollmentRepository enrollmentRepository;

@Resource
private EnrollmentAppointmentRepository enrollmentAppointmentRepository;

@Resource
private ExamEventRepository examEventRepository;

Expand Down Expand Up @@ -103,6 +108,7 @@ public void setup() throws IOException, InterruptedException {
publicEnrollmentService =
new PublicEnrollmentService(
enrollmentRepository,
enrollmentAppointmentRepository,
examEventRepository,
publicEnrollmentEmailServiceMock,
publicReservationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router';
import { CustomButton, LoadingProgressIndicator } from 'shared/components';
import { APIResponseStatus, Color, Severity, Variant } from 'shared/enums';
import { useDialog } from 'shared/hooks';
import { APIResponseStatus, Color, Variant } from 'shared/enums';

import { useCommonTranslation, usePublicTranslation } from 'configs/i18n';
import { useAppDispatch } from 'configs/redux';
Expand Down Expand Up @@ -39,8 +38,6 @@ export const PublicEnrollmentAppointmentControlButtons = ({
const dispatch = useAppDispatch();
const navigate = useNavigate();

const { showDialog } = useDialog();

const handleCancelBtnClick = () => {
// FIXME
};
Expand Down
Loading

0 comments on commit 146cf07

Please sign in to comment.