Skip to content

Commit

Permalink
VKT(Backend): Improve building free enrollment email contents
Browse files Browse the repository at this point in the history
  • Loading branch information
lket committed Sep 13, 2024
1 parent 159951f commit 0094eb0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ public void sendFreeEnrollmentConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails, enrollment.getFreeEnrollment().getSource(), "enrollment");
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"enrollment"
);

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -204,8 +208,12 @@ public void sendFreeEnrollmentToQueueConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails, enrollment.getFreeEnrollment().getSource(), "queue");
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"queue"
);

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -225,10 +233,13 @@ public void sendPartiallyFreeEnrollmentConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) throws IOException, InterruptedException {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails, enrollment.getFreeEnrollment().getSource(), "queue");
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"enrollment"
);
templateParams.put("isFree", "false");
templateParams.put("type", "enrollment");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -255,10 +266,13 @@ public void sendPartiallyFreeEnrollmentToQueueConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails, enrollment.getFreeEnrollment().getSource(), "queue");
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"queue"
);
templateParams.put("isFree", "false");
templateParams.put("type", "queue");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -272,16 +286,17 @@ public void sendPartiallyFreeEnrollmentToQueueConfirmationEmail(
createEmail(recipientName, recipientAddress, subject, body, List.of(), EmailType.ENROLLMENT_TO_QUEUE_CONFIRMATION);
}

public void getFreeEmailParams(
public Map<String, Object> withFreeEmailParams(
Map<String, Object> params,
FreeEnrollmentDetails details,
FreeEnrollmentSource source,
String type
) {
params.put("isFree", true);
params.put("type", type);
params.put("source", source.name());
params.put(
Map<String, Object> freeParams = new HashMap<>(params);
freeParams.put("isFree", true);
freeParams.put("type", type);
freeParams.put("source", source.name());
freeParams.put(
"freeExamsLeftFI",
String.format(
"%s: %s/3. %s: %s/3",
Expand All @@ -291,7 +306,7 @@ public void getFreeEmailParams(
EnrollmentUtil.getFreeExamsLeft(details.oralSkillCount())
)
);
params.put(
freeParams.put(
"freeExamsLeftSV",
String.format(
"%s: %s/3. %s: %s/3",
Expand All @@ -301,5 +316,7 @@ public void getFreeEmailParams(
EnrollmentUtil.getFreeExamsLeft(details.oralSkillCount())
)
);

return freeParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<b>Oikeutettu maksuttomaan tutkintoon:</b> <span th:text="${isFree}? 'Kyllä' : 'Ei'">Ei</span><br/>
<b>Valitsemasi taidot:</b> <span th:text="${skillsFI}"></span><br/>
<b>Valitsemasi osakokeet:</b> <span th:text="${partialExamsFI}"></span><br/>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftFI)}"></th:block><b>Maksuttomia tutkintokertoja jäljellä:</b> <span th:text="${freeExamsLeftFI}"></span><br/></th>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftFI)}"><b>Maksuttomia tutkintokertoja jäljellä:</b> <span th:text="${freeExamsLeftFI}"></span><br/></th:block>
</p>
<br/>

Expand Down Expand Up @@ -102,7 +102,7 @@
<b>Rätt till avgiftsfri examen:</b> <span th:text="${isFree} ? 'Ja' : 'Nej'">Nej</span><br/>
<b>Förmågor som du har valt:</b> <span th:text="${skillsSV}"></span><br/>
<b>Delprov som du har valt:</b> <span th:text="${partialExamsSV}"></span><br/>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftSV)}"></th:block><b>Antal avgiftsfria examina kvar:</b> <span th:text="${freeExamsLeftSV}"></span><br/></th>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftSV)}"><b>Antal avgiftsfria examina kvar:</b> <span th:text="${freeExamsLeftSV}"></span><br/></th:block>
</p>
<br/>
<p><b>Information om examenstillfället</b></p>
Expand Down

0 comments on commit 0094eb0

Please sign in to comment.