diff options
Reorganized whole architecture
3 files changed, 198 insertions, 0 deletions
| -rw-r--r-- | src/Services/EventSystem.cpp | 127 | ||||
| -rw-r--r-- | src/Services/EventSystem.h | 46 | ||||
| -rw-r--r-- | src/Services/StatusCodes.h | 25 |
diff --git a/src/Services/EventSystem.cpp b/src/Services/EventSystem.cpp new file mode 100644 index 0000000..95bd1c4 --- /dev/null +++ b/src/Services/EventSystem.cpp @@ -0,0 +1,127 @@ +#include "EventSystem.h" +#include "StatusCodes.h" + +/* Private */ + +void EventSystem::updateSoonestUpcoming() { + +} + +unsigned EventSystem::indexOfEvent(const Date& date) { + // TODO: make binary search + for (unsigned i = indSoonestUpcoming; i < events.get_count(); i++) { + if (events[i].get_date().compare(date) == 0) + return i; + } + return events.get_count(); +} + +unsigned EventSystem::indexOfEvent(const char* name, const Date& date) { + unsigned ind = indexOfEvent(date); + if (ind < events.get_count() && events[ind].get_name().compare(name) == 0) + return ind; + return events.get_count(); +} + +/* Public */ + +EventSystem::EventSystem() { + events = OrderedList<Event>(); + indSoonestUpcoming = 0; +} + +EventSystem::EventSystem(const Event* events, unsigned eventCount) { + this->events = OrderedList<Event>(events, eventCount); + indSoonestUpcoming = 0; + updateSoonestUpcoming(); +} + +StatusCode EventSystem::createEvent(const Hall* hall, String name, Date date) { + if (indexOfEvent(date) < events.get_count()) + return E_EventWillOverlap; + + events.insert(Event(hall, name, date)); + return Success; +} + +StatusCode EventSystem::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 EventSystem::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 EventSystem::reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket) { + unsigned ind = indexOfEvent(name, date); + if (ind == events.get_count()) + return E_EventDoesNotExist; + + return events[ind].reserveTicket(ticket, password, note); +} + +StatusCode EventSystem::cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn) { + return cancelTicketReservation(name, date, Ticket(seatRow, seatColumn)); +} + +StatusCode EventSystem::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 EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat) { + return buyTicket(name, date, Ticket(row, seat)); +} + +StatusCode EventSystem::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 EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password) { + return buyTicket(name, date, Ticket(row, seat), password); +} + +StatusCode EventSystem::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* EventSystem::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<Ticket> EventSystem::queryTickets(const char* name, const Date& date) { + unsigned ind = indexOfEvent(name, date); + if (ind == events.get_count()) + return OrderedList<Ticket>(); + + return events[ind].get_tickets(); +} + +OrderedList<Reservation> EventSystem::queryReservations(const char* name, const Date& date) { + unsigned ind = indexOfEvent(name, date); + if (ind == events.get_count()) + return OrderedList<Reservation>(); + + return events[ind].get_reservations(); +} diff --git a/src/Services/EventSystem.h b/src/Services/EventSystem.h new file mode 100644 index 0000000..4eeac61 --- /dev/null +++ b/src/Services/EventSystem.h @@ -0,0 +1,46 @@ +#ifndef HEADER_EVENTSYSTEM +#define HEADER_EVENTSYSTEM + +#include "../List/OrderedList.hpp" +#include "../Date/Date.h" + +#include "Event.h" +#include "StatusCodes.h" + +class EventSystem { + OrderedList<Event> events; + unsigned indSoonestUpcoming; + + void updateSoonestUpcoming(); + unsigned indexOfEvent(const Date& date); + unsigned indexOfEvent(const char* name, const Date& date); + +public: + EventSystem(); + EventSystem(const Event* events, unsigned eventCount); + + StatusCode createEvent(const Hall* hall, String name, Date date); + StatusCode cancelEvent(const char* name, const Date& date); + + StatusCode reserveTicket(const char* name, const Date& date, const char* password, const char* note, unsigned seatRow, unsigned seatColumn); + StatusCode reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket); + + StatusCode cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn); + StatusCode cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket); + + StatusCode buyTicket(const char* name, const Date& date, unsigned row, unsigned seat); + StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket); + StatusCode buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password); + StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password); + + const Hall* queryEventHall(const char* name, const Date& date); + OrderedList<Ticket> queryTickets(const char* name, const Date& date); + OrderedList<Reservation> queryReservations(const char* name, const Date& date); + + void queryMostVisited(); + void queryInsufficientlyVisited(); + void reportBoughtTickets(Date start, Date end, unsigned hall); + void reportReservations(unsigned eventIndex); +}; + +#endif diff --git a/src/Services/StatusCodes.h b/src/Services/StatusCodes.h new file mode 100644 index 0000000..4068cd3 --- /dev/null +++ b/src/Services/StatusCodes.h @@ -0,0 +1,25 @@ +#ifndef HEADER_EVENTSYSTEM_STATUSCODES +#define HEADER_EVENTSYSTEM_STATUSCODES + +enum StatusCode { + Success, + + + W_TicketHadNotBeenReserved, + + + E_Generic, + E_DoesntExist, + + E_HallDoesntExist, + + E_EventWillOverlap, + E_EventDoesNotExist, + + E_TicketAlreadyBought, + E_TicketAlreadyReserved, + E_ReservationDoesNotExist, + E_WrongReservationPassword, +}; + +#endif |
