-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderSystem.cpp
110 lines (96 loc) · 2.63 KB
/
OrderSystem.cpp
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
106
107
108
109
110
#include "OrderSystem.h"
OrderSystem& OrderSystem::Get() {
if (!s_instance)
s_instance = new OrderSystem;
return *s_instance;
}
OrderSystem& OrderSystem::GetNew() {
delete s_instance;
s_instance = new OrderSystem;
return *s_instance;
}
OrderSystem* OrderSystem::s_instance;
std::string OrderSystem::GetActiveOrders() {
std::string out = "";
std::vector<Order> orders;
std::vector<Pizza> pizzas;
for (Customer& customer : s_instance->_customers) {
out += customer.GetName() + "\n";
orders = customer.GetActiveOrders();
for (int i = 0; i < orders.size(); i++) {
pizzas = orders[i].GetPizzas();
out += std::to_string(i + 1) + ")\n";
for (auto& pizza : pizzas) {
out += pizza.ToString() + "\n";
}
}
}
return out;
}
std::string OrderSystem::GetOrders() {
std::string out = "";
std::vector<Order> orders;
std::vector<Pizza> pizzas;
for (Customer& customer : s_instance->_customers) {
out += customer.GetName() + "\n";
orders = customer.GetOrders();
for (int i = 0; i < orders.size(); i++) {
pizzas = orders[i].GetPizzas();
out += std::to_string(i + 1) + ") ";
Status status = orders[i].GetStatus();
if (status == Status::Ready) {
out += "Ready\n";
} else if (status == Status::Cooking) {
out += "Cooking\n";
} else if (status == Status::Canceled) {
out += "Canceled\n";
}
for (auto& pizza : pizzas) {
out += pizza.ToString() + "\n";
}
}
}
return out;
}
void OrderSystem::AddOrder(Customer& customer, Order& order) {
order.SetId(s_instance->_id);
std::vector<Customer>& customers = s_instance->_customers;
int index = findOrder(customers, customer);
customer.AddOrder(order);
if (index == -1) {
s_instance->_customers.push_back(customer);
}
else{
customers[index].AddOrder(order);
}
s_instance->_id++;
}
int OrderSystem::findOrder(const std::vector<Customer>& customers, const Customer& customer) {
for (int i = 0; i < customers.size(); i++) {
if (customer == customers[i]) {
return i;
}
}
return -1;
}
void OrderSystem::CompleteOrder(int id) {
std::vector<Order> orders;
for (auto& customer : s_instance->_customers) {
customer.CompleteOrder(id);
}
}
void OrderSystem::CancelOrder(int id) {
std::vector<Order> orders;
for (auto& customer : s_instance->_customers) {
customer.CancelOrder(id);
}
}
void OrderSystem::DeleteOrder(Customer& customer, const int id) {
customer.DeleteOrder(id);
}
void OrderSystem::DeleteOrder(const int id) {
std::vector<Order> orders;
for (auto& customer : s_instance->_customers) {
customer.DeleteOrder(id);
}
}