Skip to content

Commit

Permalink
#318 expose ticket sold statistics, add event id in where clause
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 13, 2017
1 parent 14c5e07 commit 24b67bc
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -531,6 +531,14 @@ public List<TicketWithStatistic> getTicketsInCategory(@PathVariable("eventName")
return eventStatisticsManager.loadModifiedTickets(event.getId(), categoryId);
}

@RequestMapping(value = "/events/{eventName}/ticket-sold-statistics", method = GET)
public List<TicketSoldStatistic> getTicketSoldStatistics(@PathVariable("eventName") String eventName, @RequestParam("from") Long fromEpoch, @RequestParam("to") Long toEpoch, Principal principal) {
Event event = loadEvent(eventName, principal);
Date from = fromEpoch == null ? new Date(0) : new Date(fromEpoch);
Date to = toEpoch == null ? new Date() : new Date(toEpoch);
return eventStatisticsManager.getTicketSoldStatistics(event.getId(), from, to);
}

private Event loadEvent(String eventName, Principal principal) {
Optional<Event> singleEvent = optionally(() -> eventManager.getSingleEvent(eventName, principal.getName()));
Validate.isTrue(singleEvent.isPresent(), "event not found");
4 changes: 4 additions & 0 deletions src/main/java/alfio/manager/EventStatisticsManager.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -167,4 +168,7 @@ public Predicate<Event> noSeatsAvailable() {
};
}

public List<TicketSoldStatistic> getTicketSoldStatistics(int eventId, Date from, Date to) {
return ticketReservationRepository.getSoldStatistic(eventId, from, to);
}
}
Original file line number Diff line number Diff line change
@@ -128,9 +128,9 @@ int updateBillingData(@Bind("vatStatus") PriceContainer.VatStatus vatStatus,
@Bind("reservationId") String reservationId);


@Query("select count(ticket.id) ticket_sold, trunc(confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc")
@Query("select count(ticket.id) ticket_sold, trunc(confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where ticket.event_id = :eventId and confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc")
@QueriesOverride({
@QueryOverride(value = "select count(ticket.id) ticket_sold, date_trunc('day', confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc", db = "PGSQL"),
@QueryOverride(value = "select count(ticket.id) ticket_sold, date(confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc", db = "MYSQL")})
List<TicketSoldStatistic> getSoldStatistic(@Bind("from") Date from, @Bind("to") Date to);
@QueryOverride(value = "select count(ticket.id) ticket_sold, date_trunc('day', confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where ticket.event_id = :eventId and confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc", db = "PGSQL"),
@QueryOverride(value = "select count(ticket.id) ticket_sold, date(confirmation_ts) as day from ticket inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where ticket.event_id = :eventId and confirmation_ts is not null and confirmation_ts >= :from and confirmation_ts <= :to group by day order by day asc", db = "MYSQL")})
List<TicketSoldStatistic> getSoldStatistic(@Bind("eventId") int eventId, @Bind("from") Date from, @Bind("to") Date to);
}
Original file line number Diff line number Diff line change
@@ -172,10 +172,10 @@ public void testTicketSelection() {
Date from = DateUtils.addDays(now, -1);
Date to = DateUtils.addDays(now, 1);

assertTrue(ticketReservationRepository.getSoldStatistic(from, to).isEmpty()); // -> no reservations
assertTrue(ticketReservationRepository.getSoldStatistic(event.getId(), from, to).isEmpty()); // -> no reservations
ticketReservationManager.validateAndConfirmOfflinePayment(reservationId, event, new BigDecimal("190.00"));

assertEquals(19, ticketReservationRepository.getSoldStatistic(from, to).get(0).getTicketSoldCount()); // -> 19 tickets reserved
assertEquals(19, ticketReservationRepository.getSoldStatistic(event.getId(), from, to).get(0).getTicketSoldCount()); // -> 19 tickets reserved

assertEquals(TicketReservation.TicketReservationStatus.COMPLETE, ticketReservationManager.findById(reservationId).get().getStatus());

0 comments on commit 24b67bc

Please sign in to comment.