Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/com/SleepUp/SU/utils/email/EmailServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.SleepUp.SU.accommodation.entity.Accommodation;
import com.SleepUp.SU.reservation.entity.Reservation;
import com.SleepUp.SU.user.entity.User;
import com.SleepUp.SU.utils.email.EmailService;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,7 +21,9 @@
public class EmailServiceImpl implements EmailService {

private static final String UTF8_ENCODING = "UTF-8";
private static final String DASHBOARD_URL = "http://localhost:8080/swagger-ui/index.html#/";
private static final String DASHBOARD_URL = "http://localhost:8080/swagger-ui/index.html#";
private static final String RESERVATIONS_URL = DASHBOARD_URL + "/api/v1/reservations";
private static final String ACCOMMODATIONS_URL = DASHBOARD_URL + "/api/v1/accommodations";

private final JavaMailSender mailSender;
private final SpringTemplateEngine templateEngine;
Expand Down Expand Up @@ -98,6 +99,8 @@ private Context createFullContext(Reservation reservation, User user, BigDecimal

if (reservation != null) {
Accommodation accommodation = reservation.getAccommodation();
context.setVariable("reservationUrl", setReservationUrl(reservation));
context.setVariable("accommodationUrl", setAccommodationUrl(accommodation));
context.setVariable("accommodationName", accommodation.getName());
context.setVariable("location", accommodation.getLocation());
context.setVariable("checkInDate", reservation.getCheckInDate() != null ? reservation.getCheckInDate().toString() : "N/A");
Expand All @@ -124,6 +127,14 @@ private Context createFullContext(Reservation reservation, User user, BigDecimal
return context;
}

private String setReservationUrl(Reservation reservation) {
return RESERVATIONS_URL + "/" + reservation.getId();
}

private String setAccommodationUrl(Accommodation accommodation) {
return ACCOMMODATIONS_URL + "/" + accommodation.getId();
}

private User getOwner(Reservation reservation) {
return reservation.getAccommodation().getManagedBy();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/fragments/reservation.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>Reservation Details</h2>
<h2>Payment Summary</h2>
<ul>
<li th:if="${amount != null}"><b>Amount:</b> <span th:text="${amount} + ' €'">Amount</span></li>
<li th:if="${discountAmount != null}"><b>Discount:</b> <span th:text="${discountAmount}">Discount</span></li>
<li th:if="${discountAmount != null}"><b>Discount:</b> <span th:text="${discountAmount} + ' €'">Discount</span></li>
</ul>
</section>

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/guest_reminder.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
You can view your reservation details and manage your stay by logging into your SleepUp dashboard.
</p>

<div th:replace="fragments/link :: link(${dashboardUrl}, #{reservation.button})">View Reservation</div>
<div th:replace="fragments/link :: link(${reservationUrl}, 'View Reservation')"></div>

</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p th:text="#{reservation.confirmed.dashboard}">You can manage your reservation or view more details by logging into your
SleepUp dashboard.</p>

<div th:replace="fragments/link :: link(${dashboardUrl}, #{reservation.button})">View Reservation</div>
<div th:replace="fragments/link :: link(${reservationUrl}, 'View Reservation')"></div>

</div>
</body>
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/templates/owner_cancellationByGuest.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
If you have any questions or need assistance, feel free to contact our support team.
</p>

<div th:replace="fragments/link :: link(${dashboardUrl}, #{accommodation.button})">View Accommodation</div>
<div th:replace="fragments/link :: link(${accommodationUrl}, 'View Accommodation')"></div>

</div>
</body>
</html>
3 changes: 2 additions & 1 deletion src/main/resources/templates/owner_reminder.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
You can view the reservation details and manage the guest's stay by logging into the SleepUp dashboard.
</p>

<div th:replace="fragments/link :: link(${dashboardUrl}, #{reservation.button})">View Reservation</div>
<div th:replace="fragments/link :: link(${reservationUrl}, 'View Reservation')"></div>

</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<div th:replace="fragments/reservation-wrapper :: reservationDetailsForOwner"></div>

<div th:replace="fragments/link :: link(${dashboardUrl}, #{reservation.button})">View Reservation</div>
<div th:replace="fragments/link :: link(${reservationUrl}, 'View Reservation')"></div>

</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void setUp() {
accommodation.setManagedBy(owner);

reservation = new Reservation();
reservation.setId(1L);
reservation.setUser(guest);
reservation.setAccommodation(accommodation);
reservation.setCheckInDate(LocalDate.now().plusDays(10));
Expand All @@ -52,7 +53,7 @@ void setUp() {
@Test
public void testSendWelcomeEmail() throws MessagingException, InterruptedException {
emailService.sendWelcomeEmail(guest);
Thread.sleep(1000); // wait for MailHog to receive email
Thread.sleep(1000);
}

@Test
Expand Down
Loading