Search in sources :

Example 1 with TicketInfo

use of alfio.controller.api.v2.model.TicketInfo in project alf.io by alfio-event.

the class TicketApiV2Controller method getTicketInfo.

@GetMapping("/api/v2/public/event/{eventName}/ticket/{ticketIdentifier}")
public ResponseEntity<TicketInfo> getTicketInfo(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier) {
    // TODO: cleanup, we load useless data here!
    var oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (oData.isEmpty()) {
        return ResponseEntity.notFound().build();
    }
    var data = oData.get();
    TicketReservation ticketReservation = data.getMiddle();
    Ticket ticket = data.getRight();
    Event event = data.getLeft();
    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId());
    boolean deskPaymentRequired = Optional.ofNullable(ticketReservation.getPaymentMethod()).orElse(PaymentProxy.STRIPE).isDeskPaymentRequired();
    // 
    var validityStart = Optional.ofNullable(ticketCategory.getTicketValidityStart(event.getZoneId())).orElse(event.getBegin());
    var validityEnd = Optional.ofNullable(ticketCategory.getTicketValidityEnd(event.getZoneId())).orElse(event.getEnd());
    var sameDay = validityStart.truncatedTo(ChronoUnit.DAYS).equals(validityEnd.truncatedTo(ChronoUnit.DAYS));
    var messageSource = messageSourceManager.getMessageSourceFor(event);
    var formattedDates = Formatters.getFormattedDates(event, messageSource, event.getContentLanguages());
    return ResponseEntity.ok(new TicketInfo(ticket.getFullName(), ticket.getEmail(), ticket.getUuid(), ticketCategory.getName(), ticketReservation.getFullName(), ticketReservationManager.getShortReservationID(event, ticketReservation), deskPaymentRequired, event.getTimeZone(), DatesWithTimeZoneOffset.fromEvent(event), sameDay, formattedDates.beginDate, formattedDates.beginTime, formattedDates.endDate, formattedDates.endTime));
}
Also used : TicketInfo(alfio.controller.api.v2.model.TicketInfo)

Aggregations

TicketInfo (alfio.controller.api.v2.model.TicketInfo)1