From e390a9f03be2407b0670ac6887150306b8f8541b Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Thu, 13 Jun 2019 15:33:52 +0200 Subject: [PATCH] remove use of reservationController.reSendReservationConfirmationEmail in reservation api v2 controller #588 --- .../v2/user/ReservationApiV2Controller.java | 20 ++++++++++++------- .../user/ReservationFlowIntegrationTest.java | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/alfio/controller/api/v2/user/ReservationApiV2Controller.java b/src/main/java/alfio/controller/api/v2/user/ReservationApiV2Controller.java index a1b27da090..056d356dc6 100644 --- a/src/main/java/alfio/controller/api/v2/user/ReservationApiV2Controller.java +++ b/src/main/java/alfio/controller/api/v2/user/ReservationApiV2Controller.java @@ -54,6 +54,7 @@ import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.springframework.web.servlet.support.RequestContextUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -284,13 +285,18 @@ public ResponseEntity> validateToOverview(@PathVariab @PostMapping("/event/{eventName}/reservation/{reservationId}/re-send-email") public ResponseEntity reSendReservationConfirmationEmail(@PathVariable("eventName") String eventName, - @PathVariable("reservationId") String reservationId, HttpServletRequest request) { - var res = reservationController.reSendReservationConfirmationEmail(eventName, reservationId, request); - if(res.endsWith("confirmation-email-sent=true")) { - return ResponseEntity.ok(true); - } else { - return ResponseEntity.ok(false); - } + @PathVariable("reservationId") String reservationId, + @RequestParam("lang") String lang) { + + var res = eventRepository.findOptionalByShortName(eventName).map(event -> + ticketReservationManager.findById(reservationId).map(ticketReservation -> { + Locale locale = Locale.forLanguageTag(lang); + ticketReservationManager.sendConfirmationEmail(event, ticketReservation, locale); + return true; + }).orElse(false) + ).orElse(false); + + return ResponseEntity.ok(res); } diff --git a/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java b/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java index 1a4863931b..0cd1a8174d 100644 --- a/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java +++ b/src/test/java/alfio/controller/api/v2/user/ReservationFlowIntegrationTest.java @@ -558,7 +558,7 @@ public void reservationFlowTest() throws Exception { assertFalse(orderSummary.getNotYetPaid()); - var confRes = reservationApiV2Controller.reSendReservationConfirmationEmail(event.getShortName(), reservationId, new MockHttpServletRequest()); + var confRes = reservationApiV2Controller.reSendReservationConfirmationEmail(event.getShortName(), reservationId, "en"); assertEquals(HttpStatus.OK, confRes.getStatusCode()); assertTrue(confRes.getBody());