Search in sources :

Example 1 with ReservationForm

use of alfio.controller.form.ReservationForm in project alf.io by alfio-event.

the class ReservationFlowIntegrationTest method reserveTicket.

private String reserveTicket(String eventName) {
    ReservationForm reservationForm = new ReservationForm();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    ServletWebRequest servletWebRequest = new ServletWebRequest(request);
    BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation");
    Model model = new BindingAwareModelMap();
    RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
    TicketReservationModification ticketReservation = new TicketReservationModification();
    ticketReservation.setAmount(1);
    ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new));
    reservationForm.setReservation(Collections.singletonList(ticketReservation));
    return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH);
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) BindingAwareModelMap(org.springframework.validation.support.BindingAwareModelMap) ReservationForm(alfio.controller.form.ReservationForm) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) TicketReservationModification(alfio.model.modification.TicketReservationModification)

Example 2 with ReservationForm

use of alfio.controller.form.ReservationForm in project alf.io by alfio-event.

the class EventController method makeSimpleReservation.

private String makeSimpleReservation(String eventName, ServletWebRequest request, RedirectAttributes redirectAttributes, Locale locale, String trimmedCode, Event event, int ticketCategoryId) {
    ReservationForm form = new ReservationForm();
    form.setPromoCode(trimmedCode);
    TicketReservationModification reservation = new TicketReservationModification();
    reservation.setAmount(1);
    reservation.setTicketCategoryId(ticketCategoryId);
    form.setReservation(Collections.singletonList(reservation));
    return validateAndReserve(eventName, form, new BeanPropertyBindingResult(form, "reservationForm"), request, redirectAttributes, locale, event);
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ReservationForm(alfio.controller.form.ReservationForm) TicketReservationModification(alfio.model.modification.TicketReservationModification)

Aggregations

ReservationForm (alfio.controller.form.ReservationForm)2 TicketReservationModification (alfio.model.modification.TicketReservationModification)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 Model (org.springframework.ui.Model)1 BindingResult (org.springframework.validation.BindingResult)1 BindingAwareModelMap (org.springframework.validation.support.BindingAwareModelMap)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)1 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)1