-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (87 loc) · 3.72 KB
/
main.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
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
import classes.user as user_class
import classes.database as database_class
from utils.utilities import MaxAttemptsExceededError, create_new_course, create_new_user, enroll_user_to_course, login_flow, quit_program, validate_menu_input, reset_screen, view_all_course_students, view_all_courses, view_all_enrollments, view_all_student_courses, view_all_users, view_my_courses
db = database_class.Database()
def main():
reset_screen()
CURRENT_USER: user_class.Admin | user_class.Student | None = None
try:
while not CURRENT_USER:
try:
CURRENT_USER = login_flow(db)
except MaxAttemptsExceededError as e:
quit_program(f"{e}")
except Exception as e:
print(f"\nAn unkowned error occured {e}")
if isinstance(CURRENT_USER, user_class.Admin):
"""
Admin flow with various actions.
"""
while True:
print(f"\nHi {CURRENT_USER.name}, Menu:")
print("1. View all users")
print("2. View all courses")
print("3. View all enrollments")
print("4. View student courses")
print("5. View course student")
print("6. Create a new student")
print("7. Create a new admin")
print("8. Create a new course")
print("9. Enroll a user to a course")
print("10. Exit")
choice = input("Enter your choice (1-10): ")
if not validate_menu_input(choice, 1, 10):
print("\nInvalid option. Please try again.")
continue
# View all users
if choice == "1":
view_all_users(db, CURRENT_USER)
# View all courses
if choice == "2":
view_all_courses(db, CURRENT_USER)
# View all enrollments
if choice == "3":
view_all_enrollments(db, CURRENT_USER)
# View student courses
if choice == "4":
view_all_student_courses(db)
# View course student
if choice == "5":
view_all_course_students(db)
# Create a new student
if choice == "6":
create_new_user(db, CURRENT_USER, "student")
# Create a new admin
if choice == "7":
create_new_user(db, CURRENT_USER, "admin")
# Create a new course
if choice == "8":
create_new_course(db, CURRENT_USER)
# Enroll a user to a course
if choice == "9":
enroll_user_to_course(db, CURRENT_USER)
# Exit
if choice == "10":
quit_program("Good bye.")
if isinstance(CURRENT_USER, user_class.Student):
"""
Student flow with various actions.
"""
while True:
print(f"\nHi {CURRENT_USER.name}, Menu:")
print("1. View my courses")
print("2. Exit")
choice = input("Enter your choice (1-2): ")
if not validate_menu_input(choice, 1, 2):
print("\nInvalid option. Please try again.")
continue
# View my courses
if choice == "1":
view_my_courses(db, CURRENT_USER)
# Exit
if choice == "2":
quit_program("Good bye.")
except KeyboardInterrupt:
print("\nExited by user.")
if __name__ == "__main__":
main()