-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.py
80 lines (67 loc) · 2.62 KB
/
User.py
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
from Cart import Cart
from RoomReserved import RoomReserved
from Reservation import Reservation
reservation_list = []
class Account():
def __init__(self, username, password, email, phone_number):
self._username = username
self._password = password
self._email = email
self._phone_number = phone_number
class User(Account):
def __init__(self, username, password, email, phone_number, full_name):
super().__init__(username, password, email, phone_number)
self.__full_name = full_name
self.__reservations = []
self.__create_cart()
def add_to_cart(self, roomtype, check_in_date, check_out_date):
room = self.__get_room(roomtype, check_in_date, check_out_date)
if(room):
locked_room = RoomReserved(room, check_in_date, check_out_date)
reservation_list.append(locked_room)
self.cart.add(locked_room)
return "Success"
else:
return "Sorry room full"
def check_out(self):
makepayment = 1
if(makepayment == 1):
for room in self.cart.room_list:
room.status = "success"
self.__reservations.append(Reservation(self.cart.room_list, 1))
self.cart.clear_cart()
return True
else:
return False
def login(self):
if self._username == self._username and self._password == self._password:
return 'User login successful!'
else:
return 'Login failed..'
def __create_cart(self):
self.__cart = Cart(self)
def __get_room(self, roomtype, check_in_date, check_out_date):
for room in roomtype.room_list:
temp = []
for roomreserved in reservation_list:
if roomreserved.id == room.id and roomreserved.status != "fail":
temp.append(roomreserved)
intersect = 0
for roomreserved in temp:
for date in range(roomreserved.check_in_date, roomreserved.check_out_date):
if date < check_out_date and date >= check_in_date:
intersect+=1
break
if(intersect == 0):
return room
return None
@property
def cart(self):
return self.__cart
@property
def reservations(self):
return self.__reservations
class Admin(Account):
def __init__(self, username, password, email, phone_number, name):
super().__init__(username, password, email, phone_number)
self.__name = name