Website Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commitb3d493796c97178f597ecf97e7c1ae46e566fe9c (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 21:24:07 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 21:24:07 +0300
Filescd7364f8d9f6e8ed7da87363e5e04c47ca02e8b1 /src
FMI-OOP-P1_TicketSystem-b3d493796c97178f597ecf97e7c1ae46e566fe9c.tar
FMI-OOP-P1_TicketSystem-b3d493796c97178f597ecf97e7c1ae46e566fe9c.tar.gz
FMI-OOP-P1_TicketSystem-b3d493796c97178f597ecf97e7c1ae46e566fe9c.zip
Parentbf7689ba06764b72a6212549a5c8a39e294cceee (diff)
Fully documented everything in Services
5 files changed, 141 insertions, 14 deletions
-rw-r--r--src/Services/EventService.cpp97
-rw-r--r--src/Services/EventService.h26
-rw-r--r--src/Services/HallService.cpp12
-rw-r--r--src/Services/HallService.h10
-rw-r--r--src/Services/StatusCode.h10
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())
diff --git a/src/Services/EventService.h b/src/Services/EventService.h
index c56620b..f6c94ca 100644
--- a/src/Services/EventService.h
+++ b/src/Services/EventService.h
@@ -1,46 +1,64 @@
#ifndef HEADER_SERVICES_EVENTSERVICE
#define HEADER_SERVICES_EVENTSERVICE
+/*! \file EventService.h
+ * \brief Stores the declaration of class EventService
+ */
+
#include "../Generic/List/OrderedList.hpp"
#include "../Generic/Date/Date.h"
#include "../Models/Event.h"
#include "HallService.h"
#include "StatusCode.h"
+/*! \brief Each EventService stores all events and a pointer to HallService
+ */
class EventService {
OrderedList<Event> events;
- unsigned indSoonestUpcoming;
const HallService* hs;
- void updateSoonestUpcoming();
unsigned indexOfEvent(const char* name, const Date& date);
public:
+ //! Sets HallService pointer and initializes events List
EventService(const HallService* hs);
+ //! Sets HallService pointer and copies values from events into events List
EventService(const HallService* hs, const Event* events, unsigned eventCount);
+ //! Creates an Event, with the given hallNumber, name and date
StatusCode createEvent(int hallNumber, const String& name, const Date& date);
+ //! Cancels an Event with the given name and date
StatusCode cancelEvent(const char* name, const Date& date);
+ //! Creates a Reservation for an Event by name and date
StatusCode reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket);
-
+ //! Cancels a Reservation for a ticket
StatusCode cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket);
-
+ //! Whether a ticket is a reserved or not
StatusCode ticketIsReserved(const char* name, const Date& date, const Ticket& ticket);
+ //! Buys ticket, assuming it is reserved and stores the reservation note
StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password, String* reservationNoteOutput);
+ //! Buys ticket, assuming it isn't reserved
StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket);
+ //! Creates a special String for status of all seats in given Event (by name and date) and returns seatsPerRow in given pointer
String createSeatingString(const char* name, const Date& date, unsigned* seatsPerRow);
+ //! \return A List of topN most watched Events
List<Event> queryMostWatched(unsigned topN);
+ //! \return A List of events which have attracted sales of less than 10% of the Hall's seat
List<Event> queryInsufficientlyVisited();
+ //! Creates a report that lists all Events (with given name and date) and their reserved tickets
StatusCode reportReservations(const char* name, const Date& date);
+ //! Creates a report that Lists all Events (with given name and date) and number of bought tickets
StatusCode reportBoughtTickets(int hallNumber, const Date& start, const Date& end, bool all = false);
+ //! Loads Events from a database file
StatusCode load();
+ //! Saves Events to a database file
StatusCode save();
};
diff --git a/src/Services/HallService.cpp b/src/Services/HallService.cpp
index b85746e..20c7a0f 100644
--- a/src/Services/HallService.cpp
+++ b/src/Services/HallService.cpp
@@ -9,6 +9,12 @@ const OrderedList<Hall>& HallService::get_halls() const {
return halls;
}
+/*!
+ * Looks for file named "hallsDatabse.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 HallService::load() {
std::ifstream inFile("hallsDatabase.fmits");
if (!inFile.is_open())
@@ -19,6 +25,12 @@ StatusCode HallService::load() {
return Success;
}
+/*!
+ * Looks for file named "hallsDatabse.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 HallService::save() {
std::ofstream outFile("hallsDatabase.fmits");
if (!outFile.is_open())
diff --git a/src/Services/HallService.h b/src/Services/HallService.h
index cad02d3..09bda89 100644
--- a/src/Services/HallService.h
+++ b/src/Services/HallService.h
@@ -1,19 +1,29 @@
#ifndef HEADER_SERVICES_HALLSERVICE
#define HEADER_SERVICES_HALLSERVICE
+/*! \file HallService.h
+ * \brief Stores the declaration of class HallService
+ */
+
#include "../Generic/List/OrderedList.hpp"
#include "../Models/Hall.h"
#include "StatusCode.h"
+/*! \brief Each HallService stores all halls
+ */
class HallService {
OrderedList<Hall> halls;
public:
+ //! Copies halls from parameters
HallService(const Hall* halls, unsigned hallCount);
+ //! Returns a constant reference to halls
const OrderedList<Hall>& get_halls() const;
+ //! Loads Halls to a database file
StatusCode load();
+ //! Saves Halls to a database file
StatusCode save();
};
diff --git a/src/Services/StatusCode.h b/src/Services/StatusCode.h
index c09e4f9..3813e87 100644
--- a/src/Services/StatusCode.h
+++ b/src/Services/StatusCode.h
@@ -1,6 +1,16 @@
#ifndef HEADER_SERVICES_STATUSCODE
#define HEADER_SERVICES_STATUSCODE
+/*! \file StatusCode.h
+ * \brief Stores declaration of enum StatusCode
+ */
+
+/*! \brief Used for communication between Services and what uses them
+ *
+ * Most functions in Services return a StatusCode.
+ *
+ * Those starting with W should be considered Warning, and those starting with E should be considered Errors.
+ */
enum StatusCode {
Success,