/** * Order new ticket * * @param departureDate * @param arrivalCity * @param departureCity * @param personName * @param personSurname * @return unique ticket number in system */ @GET @Path("/orderTicket") @Produces(MediaType.TEXT_PLAIN) public String orderTicket( @QueryParam("departureDate") String departureDate, @QueryParam("arrivalCity") String arrivalCity, @QueryParam("departureCity") String departureCity, @QueryParam("personName") String personName, @QueryParam("personSurname") String personSurname) { String ret = ""; try { long orderedTicketId = persistanceModel.getLastID(true); orderedTicketId++; Ticket ticket = new Ticket(); ticket.setOrderedSign(true); Date date = new SimpleDateFormat("MM.DD.YY").parse(departureDate); ticket.setDepartureDate(date); ticket.setArrivalCity(arrivalCity); ticket.setDepartureDate(date); ticket.setTicketId(orderedTicketId); ticket.setPersonId(persistanceModel.selectPersonIdByName(personName)); persistanceModel.insertTicket(ticket); ret = String.valueOf(orderedTicketId); } catch (Exception ex) { ret = ""; } finally { return ret; } }
/** * Delete ticket method * * @param ticketId * @return true if ticket deleted successfully */ @POST @Path("/delete") @Produces(MediaType.TEXT_PLAIN) public Response delete(@QueryParam("ticketId") int ticketId) { Response response; if (persistanceModel.deleteTicket(ticketId)) { response = Response.ok().build(); } else { response = Response.status(666).build(); } return response; }
/** * Payment status * * @param ticketId * @return true if ticket paid */ @POST @Path("/buyTicket") @Produces(MediaType.TEXT_PLAIN) public Response buyTicket(@QueryParam("ticketId") int ticketId) { Response response; if (persistanceModel.updatePaymentStatus(ticketId)) { response = Response.ok().build(); } else { response = Response.status(666).build(); } return response; }
/** * Get human readable ticket by id * * @param ticketId * @return return ticket if exists */ @POST @Path("/getTickByID") @Produces(MediaType.TEXT_PLAIN) public String getTickByID(@QueryParam("ticketId") int ticketId) { return persistanceModel.selectTicketByID(ticketId).toString(); }