Skip to content

Commit

Permalink
#588 add validate to overview step
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Mar 26, 2019
1 parent 2fc35fb commit 4a5b408
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public String showConfirmationPage(@PathVariable("eventName") String eventName,
@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}/validate-to-overview", method = RequestMethod.POST)
public String validateToOverview(@PathVariable("eventName") String eventName, @PathVariable("reservationId") String reservationId,
ContactAndTicketsForm contactAndTicketsForm, BindingResult bindingResult,
Model model, HttpServletRequest request, Locale locale, RedirectAttributes redirectAttributes) {
HttpServletRequest request, RedirectAttributes redirectAttributes) {

Optional<Event> eventOptional = eventRepository.findOptionalByShortName(eventName);
return redirectIfNotValid(contactAndTicketsForm.isBackFromOverview(), contactAndTicketsForm.shouldCancelReservation(), eventName, reservationId, request, eventOptional)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package alfio.controller.api.v2.user;

import alfio.controller.ReservationController;
import alfio.controller.form.ContactAndTicketsForm;
import alfio.controller.support.TicketDecorator;
import alfio.model.TicketCategory;
import lombok.AllArgsConstructor;
Expand All @@ -25,11 +26,12 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -56,15 +58,31 @@ public static class TicketsByTicketCategory {
@PathVariable("reservationId") String reservationId,
Model model,
Locale locale) {
String res = reservationController.showBookingPage(eventName, reservationId, model, locale);
var res = reservationController.showBookingPage(eventName, reservationId, model, locale);
//FIXME temporary
model.addAttribute("viewState", res);

//overwrite with a better model object...
var ticketsByCategory = (List<Pair<TicketCategory, List<TicketDecorator>>>) model.asMap().get("ticketsByCategory");
model.addAttribute("ticketsByCategory", ticketsByCategory.stream().map(a -> new TicketsByTicketCategory(a.getKey(), a.getValue())).collect(Collectors.toList()));

if (ticketsByCategory != null) {
model.addAttribute("ticketsByCategory", ticketsByCategory.stream().map(a -> new TicketsByTicketCategory(a.getKey(), a.getValue())).collect(Collectors.toList()));
}
return new ResponseEntity<>(model.asMap(), HttpStatus.OK);
}

@PostMapping("/event/{eventName}/reservation/{reservationId}/validate-to-overview")
public ResponseEntity<Map<String, ?>> validateToOverview(@PathVariable("eventName") String eventName,
@PathVariable("reservationId") String reservationId,
@RequestBody ContactAndTicketsForm contactAndTicketsForm,
BindingResult bindingResult,
HttpServletRequest request,
RedirectAttributes redirectAttributes) {

var res = reservationController.validateToOverview(eventName, reservationId, contactAndTicketsForm, bindingResult, request, redirectAttributes);
var model = new HashMap<String, Object>();
model.put("viewState", res);
//model.put("bindingResult", bindingResult.getModel()); <- cause 400 error
return new ResponseEntity<>(model, HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private String payOffline(String eventName, String reservationIdentifier) {
MockHttpServletRequest request = new MockHttpServletRequest();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();

reservationController.validateToOverview(eventName, reservationIdentifier, contactAndTicketsForm, bindingResult, model, request, Locale.ENGLISH, redirectAttributes);
reservationController.validateToOverview(eventName, reservationIdentifier, contactAndTicketsForm, bindingResult, request, redirectAttributes);

Assert.assertEquals("/event/overview", reservationController.showOverview(eventName, reservationIdentifier, Locale.ENGLISH, model, new MockHttpSession()));

Expand Down

0 comments on commit 4a5b408

Please sign in to comment.