-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.cpp
115 lines (97 loc) · 2.44 KB
/
Controller.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
111
112
113
114
#include "Controller.h"
Controller::~Controller()
{
}
FileRepository Controller::getRepo()
{
return repo;
}
int Controller::addFilmToRepo(const std::string & title, const std::string & genre, unsigned year)
{
// try
// {
Film f(title, genre, year);
//repo.add(f);
return repo.add(f);
// }
// catch (FilmNotFound& e)
// {
//return -1;
//}
}
void Controller::updateFilmFromRepo(unsigned pos, const std::string & newTitle, const std::string & newGenre, const unsigned newYear)
{
repo.update(pos, newTitle, newGenre, newYear);
}
int Controller::deleteFilmFromRepo(const std::string & title, unsigned year)
{
// try {
Film f = repo.findByID(title, year);
if (f.getTitle() != "")
{
repo.remove(f); //fileREPO remove
return 0;
}
else
return -1;
// }
// catch (FilmNotFound& e)
// {
// return -1;
// }
}
std::vector<Film> Controller::getFilmsGenre(const std::string& genre) const
{
std::vector<Film> allFilms = repo.getFilms();
if (genre == "")
return allFilms;
else {
std::vector<Film> foundFilms;
for (unsigned i = 0; i < allFilms.size(); i++)
if (allFilms[i].getGenre() == genre)
foundFilms.push_back(allFilms[i]);
return foundFilms;
}
}
void Controller::incLikes(const std::string& title, unsigned year)
{
Film f = repo.findByID(title, year);
repo.incLikes(f);
}
void Controller::addNewUserToRepo(const User & u)
{
repo.addUser(u);
}
int Controller::deleteFilmFromWatchlist(const std::string & userName, const std::string & title, unsigned year)
{
// try
// {
Film f = repo.findByID(title, year);
repo.deleteFromWatchlist(userName, f);
return 0;
}
int Controller::addFilmToWatchlist(const std::string & userName, const Film & f)
{
//return repo.addUsersFilmToWatchlist(userName, f
repo.addWatchList(userName, f);
return 0;
}
void Controller::selectFileType(const std::string & userName, const std::string & fileType)
{
if (fileType == "html")
repo.init_html(userName + "Watchlist.html");
else if (fileType == "csv")
repo.init_csv(userName + "Watchlist.csv");
}
void Controller::setListForFileRepo(const std::vector<Film>& v)
{
repo.setVectorToFile(v);
}
void Controller::saveFile()
{
repo.save_file();
}
void Controller::openFileInApp()
{
repo.open();
}