-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cpp
More file actions
126 lines (97 loc) · 3.77 KB
/
Controller.cpp
File metadata and controls
126 lines (97 loc) · 3.77 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "Controller.h"
Controller::ElectricController::ElectricController(shared_ptr<Repository::CrudRepository> &repo) : repo(repo) {}
void Controller::ElectricController::add_car_manager(string brand, string model, int year_of_registration, float price, float loading_time, float range) {
if (year_of_registration < 1900)
throw exception();
else {
this->repo->add_car_manager(brand, model, year_of_registration, price, loading_time, range);
}
}
void Controller::ElectricController::delete_car_manager(int id) {
bool found = false;
for(Domain::Elektroauto car : this->repo->get_cars())
if(car.getId() == id)
found = true;
if(!found)
throw exception();
else{
this->repo->delete_car_manager(id);
}
}
void Controller::ElectricController::modify_car_manager(int id, float kilometer,
float price, float loading_time, float range) {
bool found = false;
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getId() == id)
found = true;
if (!found)
throw exception();
else {
this->repo->modify_car_manager(id, kilometer, price, loading_time,
range);
}
}
vector<Domain::Elektroauto> Controller::ElectricController::filter_brand_model(int option, string filter_by) {
vector<Domain::Elektroauto> filter_cars = {};
if (option == 1) {
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getBrand() == filter_by)
filter_cars.emplace_back(car);
}
if (option == 2) {
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getModel() == filter_by)
filter_cars.emplace_back(car);
}
return filter_cars;
}
vector<Domain::Elektroauto> Controller::ElectricController::sort_by_price() {
vector<Domain::Elektroauto> filter_cars = {};
for (Domain::Elektroauto car: this->repo->get_cars())
filter_cars.emplace_back(car);
std::sort(filter_cars.begin(), filter_cars.end(),
[](Domain::Elektroauto &car1, Domain::Elektroauto &car2) { return car1.getPrice() < car2.getPrice(); });
return filter_cars;
}
vector<Domain::Elektroauto> Controller::ElectricController::filter_by_age(int year_of_registration) {
vector<Domain::Elektroauto> filter_cars = {};
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getYearOfRegistration() == year_of_registration)
filter_cars.emplace_back(car);
return filter_cars;
}
vector<Domain::Elektroauto> Controller::ElectricController::filter_by_kilometer(float kilometer) {
vector<Domain::Elektroauto> filter_cars = {};
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getKilometer() <= kilometer)
filter_cars.emplace_back(car);
return filter_cars;
}
void Controller::ElectricController::add_car_client(int id, string kunde) {
bool found = false;
for (Domain::Elektroauto car: this->repo->get_cars())
if (car.getId() == id)
found = true;
if (!found)
throw exception();
else {
this->repo->add_car_client(id,kunde);
}
}
void Controller::ElectricController::delete_car_client(int id, string kunde) {
bool found = false;
for (Domain::Elektroauto car: this->repo->get_fav_cars())
if (car.getId() == id)
found = true;
if (!found)
throw exception();
else {
this->repo->delete_car_client(id, kunde);
}
}
vector<Domain::Elektroauto> Controller::ElectricController::get_cars() {
return this->repo->get_cars();
}
vector<Domain::Elektroauto> Controller::ElectricController::get_fav_cars() {
return this->repo->get_fav_cars();
}