From 17d2444480bd0fc9ad0d0ed4cfb9372d4cd87895 Mon Sep 17 00:00:00 2001 From: Michal Badin <xbadin@fi.muni.cz> Date: Mon, 8 May 2023 21:05:20 +0200 Subject: [PATCH] fix(new-component-email): Added email template --- .../pa165/service/NotificationService.java | 14 +++-- .../templates/new-component-email.html | 61 +++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 notification/src/main/resources/templates/new-component-email.html diff --git a/notification/src/main/java/cz/muni/pa165/service/NotificationService.java b/notification/src/main/java/cz/muni/pa165/service/NotificationService.java index 5ae703c..542f03d 100644 --- a/notification/src/main/java/cz/muni/pa165/service/NotificationService.java +++ b/notification/src/main/java/cz/muni/pa165/service/NotificationService.java @@ -38,12 +38,16 @@ public class NotificationService { public ConfirmationDto notifyNewComponent(CarComponentNotificationDto carComponentNotificationDto) { var c = carComponentNotificationDto.getCarComponent(); var subject = "New component: " + c.getInformation(); - var text = "New component was added to Formula team management core.\n" - + "\nType: " + c.getComponentType() - + "\nInformation: " + c.getInformation() - + "\nWeight: " + c.getWeight(); - return sendEmail(subject, text, carComponentNotificationDto.getReceivers()); + Context ctx = new Context(); + ctx.setVariable("id", c.getId()); + ctx.setVariable("type", c.getComponentType()); + ctx.setVariable("info", c.getInformation()); + ctx.setVariable("weight", c.getWeight()); + + var htmlContent = templateEngine.process("new-component-email", ctx); + + return sendEmail(subject, htmlContent, carComponentNotificationDto.getReceivers()); } public ConfirmationDto notifyNewApplication(ApplicationNotificationDto applicationNotificationDto) { diff --git a/notification/src/main/resources/templates/new-component-email.html b/notification/src/main/resources/templates/new-component-email.html new file mode 100644 index 0000000..cb066f1 --- /dev/null +++ b/notification/src/main/resources/templates/new-component-email.html @@ -0,0 +1,61 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org" lang="en"> +<head> + <meta charset="utf-8"> + <title>Application for Formula Driver Position</title> + <style> + body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f6f6f6; + } + + .container { + max-width: 625px; + margin: 0 auto; + background-color: #fff; + padding: 20px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + position: relative; + } + + h1 { + font-size: 24px; + font-weight: bold; + margin: 0; + text-align: left; + } + + p { + font-size: 16px; + line-height: 1.5; + margin: 20px 0; + text-align: justify; + } + </style> +</head> +<body> +<div class="container"> + <h1>New component was added to Formula team management core</h1> + <table> + <tr> + <td>Id:</td> + <td th:text="${id}"></td> + </tr> + <tr> + <td>Component type:</td> + <td th:text="${type}"></td> + </tr> + <tr> + <td>Information:</td> + <td th:text="${info}"></td> + </tr> + <tr> + <td>Weight:</td> + <td th:text="${weight} + 'kg'"></td> + </tr> + </table> +</div> +</body> +</html> \ No newline at end of file -- GitLab