diff options
Fully documented everything in Services
1 files changed, 87 insertions, 10 deletions
| -rw-r--r-- | src/Services/EventService.cpp | 97 |
diff --git a/src/Services/EventService.cpp b/src/Services/EventService.cpp index 0e8692f..0ab223f 100644 --- a/src/Services/EventService.cpp +++ b/src/Services/EventService.cpp @@ -5,12 +5,7 @@ /* 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; @@ -27,16 +22,19 @@ bool correctReservationPassword(const Reservation& res, const char* password) { EventService::EventService(const HallService* hs) { this->hs = hs; events = OrderedList<Event>(); - indSoonestUpcoming = 0; } EventService::EventService(const HallService* hs, const Event* events, unsigned eventCount) { this->hs = hs; this->events = OrderedList<Event>(events, eventCount); - indSoonestUpcoming = 0; - updateSoonestUpcoming(); } +/*! + * Uses HallService pointer to get Hall from hallNumber + * \return E_HallDoesntExist \b if hallNumber doesn't correspond to any Hall, saved in HallService + * \return E_EventWillOverlap \b if Event's date overlaps with another event in the same Hall + * \return Success \b otherwise + */ 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()) @@ -52,6 +50,10 @@ StatusCode EventService::createEvent(int hallNumber, const String& name, const D return Success; } +/*! + * \return E_EventDoesNotExist \b if No Event with the given name and date exists + * \return Success \b otherwise + */ StatusCode EventService::cancelEvent(const char* name, const Date& date) { unsigned ind = indexOfEvent(name, date); if (ind == events.get_count()) @@ -61,6 +63,12 @@ StatusCode EventService::cancelEvent(const char* name, const Date& date) { return Success; } +/*! + * \return E_EventDoesNotExist \b if No Event with the given name and date exists + * \return E_TicketAlreadyBought \b if A ticket for the given row and seat has already been bought + * \return E_TicketAlreadyReserved \b if A reservation has already been placed on the given row and seat + * \return Success \b otherwise + */ 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()) @@ -80,6 +88,13 @@ StatusCode EventService::reserveTicket(const char* name, const Date& date, const return Success; } +/*! + * Canceling a reservation doesn't require password and doesn't return the Reservation's note + * + * \return E_EventDoesNotExist \b if No Event with the given name and date exists + * \return W_TicketHadNotBeenReserved \b Ticket hadn't been reserved in the first place + * \return Success \b otherwise + */ StatusCode EventService::cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) @@ -93,6 +108,11 @@ StatusCode EventService::cancelTicketReservation(const char* name, const Date& d return Success; } +/*! + * \return E_EventDoesNotExist \b if No Event with the given name and date exists + * \return W_TicketHadNotBeenReserved \b Ticket hadn't been reserved in the first place + * \return Success \b otherwise + */ StatusCode EventService::ticketIsReserved(const char* name, const Date& date, const Ticket& ticket) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) @@ -104,10 +124,21 @@ StatusCode EventService::ticketIsReserved(const char* name, const Date& date, co return W_TicketHadNotBeenReserved; } +/*! + * Calls buyTicket with Reservation, but sets password and noteOutput to nullptr. + * \copydetails buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password, String* reservationNoteOutput) + */ StatusCode EventService::buyTicket(const char* name, const Date& date, const Ticket& ticket) { return buyTicket(name, date, ticket, nullptr, nullptr); } +/*! + * \return E_EventDoesNotExist \b if No Event with the given name and date exists + * \return E_TicketAlreadyBought \b if A ticket for the given row and seat has already been bought + * \return E_TicketAlreadyReserved \b if The seat and row are reserved, but given password is nullptr + * \return E_WrongReservationPassword \b if The seat and row are reserved, but given password is incorrect + * \return Success \b otherwise + */ StatusCode EventService::buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password, String* reservationNoteOutput) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) @@ -133,6 +164,12 @@ StatusCode EventService::buyTicket(const char* name, const Date& date, const Tic return Success; } +/*! + * Each seat in the Hall of the Event is represented by a single character, where 'R' means the seat is reserved, 'B' means the seat is bought and ' ' if it's neither. + * + * \return Empty String \b if No Event with the given name and date exists + * \return Proper String \b otherwise + */ String EventService::createSeatingString(const char* name, const Date& date, unsigned* seatsPerRow) { unsigned eInd = indexOfEvent(name, date); if (eInd == events.get_count()) { @@ -166,6 +203,12 @@ unsigned indexToInsertWhenTicketSort(const List<Event>& elem, unsigned topN, uns return (topN < elem.get_count()) ? topN : elem.get_count(); } +/*! + * Events are sorted from index 0 to last index decreasingly by number of watchers. + * Watchers count for an Event is the amount of bought tickets. + * + * If there are less events than topN, all events are returned. + */ List<Event> EventService::queryMostWatched(unsigned topN) { List<Event> result; for (unsigned i = 0; i < events.get_count(); i++) { @@ -200,6 +243,17 @@ bool cond_event_date(const Event& e, const Date& date) { return e.get_date().compare(date) == 0; } +/*! \param name C-style string, if it is equal to "ALL", reservations from all Events on the given date will be reported + * \param date If day, month and year are equal to 0, reservations from all dates will be reported + * + * Report is saved in a file in the current directory, named "report-NAME-DATE.txt", + * where NAME is the given name, and DATE is the given date or "ALL" if the date is 0/0/0 + * + * All Events are inserted into the file with the << operator and a setting of 0b00101. + * + * \return E_FileCouldNotBeOpened \b if Report file couldn't be created + * \return Success \b otherwise + */ StatusCode EventService::reportReservations(const char* name, const Date& date) { List<Event> result; bool (*cond_name)(const Event&, const char*) = cond_event_name; @@ -225,7 +279,7 @@ StatusCode EventService::reportReservations(const char* name, const Date& date) if (!outFile.is_open()) return E_FileCouldNotBeOpened; - configureEventInsertionOp(0b101); + configureEventInsertionOp(0b00101); outFile << result; outFile.close(); @@ -240,6 +294,17 @@ bool cond_event_dates(const Event& event, const Date& start, const Date& end) { return event.get_date().compare(start) >= 0 && event.get_date().compare(end) <= 0; } +/*! \param hallNumber Number of the Event's Hall + * \param start Starting Date from which to take Events + * \param end Ending Date until which to take Evnets (including) + * + * Report is saved in a file named "boughtTickets.txt" in the current directory. + * + * All Events are inserted into the file with the << operator and a setting of 0b01001. + * + * \return E_FileCouldNotBeOpened \b if Report file couldn't be created + * \return Success \b otherwise + */ StatusCode EventService::reportBoughtTickets(int hallNumber, const Date& start, const Date& end, bool all) { List<Event> result; bool (*cond_hall)(const Event&, int) = cond_event_hallNumber; @@ -250,7 +315,7 @@ StatusCode EventService::reportBoughtTickets(int hallNumber, const Date& start, result.add(events[i]); } - std::ofstream outFile("boughtTickets.txt"); // TODO: filename + std::ofstream outFile("boughtTickets.txt"); if (!outFile.is_open()) return E_FileCouldNotBeOpened; @@ -262,6 +327,12 @@ StatusCode EventService::reportBoughtTickets(int hallNumber, const Date& start, } +/*! + * Looks for file named "eventsDatabse.fmits", which is just a binary file, and then reads it with the "read" function in events List. + * + * \return E_FileCouldNotBeOpened \b if The files couldn't be opened/Doesn't exist + * \return Success \b otherwise + */ StatusCode EventService::load() { std::ifstream inFile("eventsDatabase.fmits"); if (!inFile.is_open()) @@ -272,6 +343,12 @@ StatusCode EventService::load() { return Success; } +/*! + * Looks for file named "eventsDatabse.fmits", which is just a binary file, and then writes to it with the "write" function in events List. + * + * \return E_FileCouldNotBeOpened \b if The files couldn't be opened + * \return Success \b otherwise + */ StatusCode EventService::save() { std::ofstream outFile("eventsDatabase.fmits"); if (!outFile.is_open()) |
