@POST @Path("/bookedTickets") public List<Integer> getBookedTickets(@QueryParam(value = "projectionId") String projectionId) { ProjectionBookings projection = map.get(Long.valueOf(projectionId)); if (projection == null) { return null; } else { return projection.getBookedPlacesArray(); } }
@POST @Path("/book") public Response bookTicket( @QueryParam(value = "projectionId") String projectionIdString, @QueryParam(value = "seat") String selectedSeats) { if (!isInitialized) { map = init(); isInitialized = true; deleterThread.start(); } synchronized (lock) { Long projectionId = Long.valueOf(projectionIdString); String[] seatNumbers = selectedSeats.split(","); List<Integer> seats = new ArrayList<>(); for (String seat : seatNumbers) { seats.add(Integer.valueOf(seat)); } if (map.containsKey(projectionId)) { ProjectionBookings projection = map.get(projectionId); List<Integer> addedSeats = new ArrayList<>(); for (Integer seat : seats) { if (projection.isTicketBooked(Integer.valueOf(seat))) { projection.removeBooked(addedSeats); return Response.status(401).build(); } else { projection.bookTicket(Integer.valueOf(seat), context.getCurrentUser()); addedSeats.add(Integer.valueOf(seat)); } } for (Integer i : addedSeats) { ticketExpirationTimes.add(projection.getTicket(i)); } return Response.ok().build(); } else { System.out.println("No such projection exists"); return Response.status(401).build(); } } }