#include "EventService.h" #include "StatusCode.h" /* Private */ void EventService::updateSoonestUpcoming() { } unsigned EventService::indexOfEvent(const char* name, const Date& date) { // TODO: binary search for (unsigned i = 0; i < events.get_count(); i++) { if (events[i].get_date().compare(date) == 0 && events[i].get_name().compare(name) == 0) return i; } return events.get_count(); } /* Public */ EventService::EventService(const HallService* hs) { this->hs = hs; events = OrderedList(); indSoonestUpcoming = 0; } EventService::EventService(const HallService* hs, const Event* events, unsigned eventCount) { this->hs = hs; this->events = OrderedList(events, eventCount); indSoonestUpcoming = 0; updateSoonestUpcoming(); } StatusCode EventService::createEvent(int hallNumber, const String& name, const Date& date) { unsigned hInd = hs->get_halls().findIndex(Hall(hallNumber)); if (hInd == hs->get_halls().get_count()) return E_HallDoesntExist; Event newEv(hallNumber, name, date); unsigned eInd = events.findIndex(newEv); if (eInd < events.get_count()) return E_EventWillOverlap; events.insert(newEv); return Success; } StatusCode EventService::cancelEvent(const char* name, const Date& date) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return E_EventDoesNotExist; events.removeAt(ind); return Success; } StatusCode EventService::reserveTicket(const char* name, const Date& date, const char* password, const char* note, unsigned seatRow, unsigned seatColumn) { return reserveTicket(name, date, password, note, Ticket(seatRow, seatColumn)); } StatusCode EventService::reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) return E_EventDoesNotExist; Reservation res(ticket, password, note); unsigned return events[ind].reserveTicket(ticket, password, note); } StatusCode EventService::cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn) { return cancelTicketReservation(name, date, Ticket(seatRow, seatColumn)); } StatusCode EventService::cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return E_EventDoesNotExist; return events[ind].cancelReservation(ticket); } StatusCode EventService::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat) { return buyTicket(name, date, Ticket(row, seat)); } StatusCode EventService::buyTicket(const char* name, const Date& date, const Ticket& ticket) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return E_EventDoesNotExist; return events[ind].buyTicket(ticket); } StatusCode EventService::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password) { return buyTicket(name, date, Ticket(row, seat), password); } StatusCode EventService::buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return E_EventDoesNotExist; return events[ind].buyTicketFromReservation(Reservation(ticket), password); } const Hall* EventService::queryEventHall(const char* name, const Date& date) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return nullptr; return &events[ind].get_hall(); } OrderedList EventService::queryTickets(const char* name, const Date& date) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return OrderedList(); return events[ind].get_tickets(); } OrderedList EventService::queryReservations(const char* name, const Date& date) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) return OrderedList(); return events[ind].get_reservations(); }