Website Summary Files Commits Branches @commit @diff @stats
path: root / src / EventSystem / EventSystem.cpp
blob: 0bbd13a9013fb8991f3c0c7553b6a59b05557c0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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) {
	unsigned ind = indexOfEvent(name, date);
	if (ind == events.get_count())
		return E_EventDoesNotExist;

	return events[ind].reserveTicket(Ticket(seatRow, seatColumn), password, note);
}

StatusCode EventSystem::cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn) {
	unsigned ind = indexOfEvent(name, date);
	if (ind == events.get_count())
		return E_EventDoesNotExist;
	
	return events[ind].cancelReservation(seatRow, seatColumn);
}

StatusCode EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat) {
	unsigned ind = indexOfEvent(name, date);
	if (ind == events.get_count())
		return E_EventDoesNotExist;

	return events[ind].buyTicket(Ticket(row, seat));
}


StatusCode EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password) {
	unsigned ind = indexOfEvent(name, date);
	if (ind == events.get_count())
		return E_EventDoesNotExist;

	return events[ind].buyTicketFromReservation(Reservation(Ticket(row, seat)), password);
}

List<Ticket> EventSystem::queryFreeTickets(const char* name, const Date& date) {
	unsigned ind = indexOfEvent(name, date);

	if (ind == events.get_count())
		return List<Ticket>();

	List<Ticket> freeTickets;

	unsigned nextIndT = 0, nextIndR = 0;
	for (unsigned r = 1; r <= events[ind].get_hall().get_rowCount(); r++) {
		for (unsigned s = 1; s <= events[ind].get_hall().get_seatsPerRow(); s++) {
			// TODO: finish
		}
	}

	return freeTickets;
}