forked from kamkali/Cinema-Booking-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
103 lines (84 loc) · 2.91 KB
/
main.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
#include <iostream>
//
// Created by Piotr on 12.11.2019.
//
#include <iostream>
#include "movie/Movie.h"
#include "room/CinemaRoom.h"
#include "room/RoomFactory.h"
#include "room/CinemaRoomFactory.h"
#include "db/Database.h"
#include "sqlite/sqlite3.h"
#include "db/QueryLoader.h"
#include "command/Command.h"
#include "command/InitializeAdminAccount.h"
#include "command/InitializeCinemaSystem.h"
#include "command/InitializeRooms.h"
#include "command/ReturnRoom.h"
#include "command/SelectOccupiedRooms.h"
#include "command/CreateSeance.h"
#include "command/DeleteMovieCommand.h"
#include "command/ListMoviesCommand.h"
#include "command/CreateMovieCommand.h"
#include "command/LoginUserCommand.h"
#include "command/RegisterUserCommand.h"
#include "command/DeleteSeance.h"
#include "command/OrderSeat.h"
#include "workflow.h"
#define DATABASE_NAME "cinema"
#define ADMIN_USERNAME "admin"
#define ADMIN_PASSWORD "admin"
#define SEATS_NUMBER 100
#define ROWS_NUMBER 10
#define ADMIN "ROLE_ADMIN"
using namespace std;
int main(int argc, char * argv[]){
Database * db;
Command * command;
command = new InitializeCinemaSystem(DATABASE_NAME);
command->execute();
db = dynamic_cast<InitializeCinemaSystem *>(command)->getDatabase();
command = new InitializeAdminAccount(db, ADMIN_USERNAME, ADMIN_PASSWORD);
command ->execute();
command = new InitializeRooms(db, 10, SEATS_NUMBER, ROWS_NUMBER);
command->execute();
RoomFactory * roomPool = dynamic_cast<InitializeRooms *>(command)->getRoomPool();
command = new SelectOccupiedRooms(db, SEATS_NUMBER/ROWS_NUMBER);
command->execute();
vector<Room*> occupiedRooms = dynamic_cast<SelectOccupiedRooms *>(command)->getOccupiedRooms();
string login;
string password;
int order;
cout << " Kuglan'n'Kali Cinema " << endl;
cout << "____________________________________" << endl;
cout << "Welcome to the Kuglan'n'Kali Cinema!" << endl;
cout << "Sign in (1)\nSign up (2)\n" << endl;
cout << "~: ";
cin >> order;
if(order == 1){
cout << "Your login: ";
cin >> login;
cout << "Your password: ";
cin >> password;
command = new RegisterUserCommand(db, login, password);
command->execute();
}
cout << "login: ";
cin >> login;
cout << "password: ";
cin >> password;
command = new LoginUserCommand(db, login, password);
command->execute();
if(dynamic_cast<LoginUserCommand *>(command)->isLogged()){
auto * loginUserCommand = dynamic_cast<LoginUserCommand *>(command);
int userId = loginUserCommand->getUserId();
bool isAdmin = loginUserCommand->isUserAdmin();
if(isAdmin)
showAdminMenu(db, roomPool, &occupiedRooms);
else
showUserMenu(db, occupiedRooms, ROWS_NUMBER, userId);
} else{
cout << "You are no authorized!" << endl;
cout << "Closing..." << endl;
}
}