Skip to content

Commit

Permalink
Final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
y-samy committed Dec 29, 2024
1 parent c879277 commit 7ea8d4b
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 55 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_executable(hotel src/main.c
src/ui/menus/reservation.h
src/ui/menus/check_in.c
src/ui/menus/check_in.h
src/ui/menus/status.h
src/ui/status.h
src/ui/menus/cancel_reservation.c
src/ui/menus/cancel_reservation.h
src/ui/menus/view_customer_details.c
Expand Down Expand Up @@ -52,6 +52,8 @@ add_executable(hotel src/main.c
src/ui/menus/edit_reservation.h
src/ui/menus/check_out.c
src/ui/menus/check_out.h
src/ui/menus/exit_menu.c
src/ui/menus/exit_menu.h
)

target_link_libraries(hotel)
Expand Down
33 changes: 8 additions & 25 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ int main()
if (!is_logged_in(login_session)) {
response = root_menu();
if (response == MENU_SIGNAL_EXIT)
exit_routine(login_session, hotel_session);
if (exit_menu(login_session, hotel_session) == MENU_SIGNAL_CANCEL)
continue;

response = login_menu(login_session);
if (response == MENU_SIGNAL_EXIT)
exit_routine(login_session, hotel_session);
if (exit_menu(login_session, hotel_session) == MENU_SIGNAL_CANCEL)
continue;
if (response == MENU_SIGNAL_CANCEL)
continue;
}

response = main_menu(hotel_session);
if (response == MENU_SIGNAL_EXIT)
exit_routine(login_session, hotel_session);
if (response == MENU_SIGNAL_EXIT_ABRUPT) {
discard_exit_routine(login_session, hotel_session);
}
if (exit_menu(login_session, hotel_session) == MENU_SIGNAL_CANCEL)
continue;
if (response == MENU_SIGNAL_CANCEL) {
logout(login_session);
continue;
}

switch (response) {
case 1:
response = reserve_room(hotel_session);
break;


case 2:
response = check_in(hotel_session);
break;
Expand Down Expand Up @@ -89,23 +89,6 @@ int main()
break;
}
if (response == MENU_SIGNAL_EXIT)
exit_routine(login_session, hotel_session);
exit_menu(login_session, hotel_session);
}
}


void exit_routine(LoginSession *login_session, HotelSession *hotel_session)
{
/* Unload user objects */
terminate_login_session(login_session);
/* Serialize and unload reservation, rooms and customer objects */
terminate_management_session(hotel_session);
exit(0);
}

void discard_exit_routine(LoginSession *login_session, HotelSession *hotel_session)
{
terminate_login_session(login_session);
discard_management_session(hotel_session);
exit(0);
}
2 changes: 1 addition & 1 deletion src/ui/menus/availability.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <libui/io.h>
#include <stdio.h>

#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"CHECK ROOM AVAILABILITY\n"\
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/cancel_reservation.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <management.h>
#include <stdio.h>

#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"CANCEL RESERVATION\n"\
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/check_in.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "check_in.h"
#include "status.h"
#include "../status.h"

#include <math.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/check_out.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "check_out.h"
#include "status.h"
#include "../status.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/edit_reservation.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "edit_reservation.h"
#include <libui/io.h>
#include "status.h"
#include "../status.h"
#include <stdio.h>
#include <stdlib.h>

Expand Down
49 changes: 49 additions & 0 deletions src/ui/menus/exit_menu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "exit_menu.h"
#include <stdlib.h>
#include <libui/io.h>
#include <status.h>

#define MENU_STATIC \
"EXIT\n"\
"----\n\n"

#define MENU_CHOICES \
"Save and exit\n" \
"Discard all session data and exit\n" \
"Return to Main Menu\n"

static void save(LoginSession *login_session, HotelSession *hotel_session)
{
/* Unload user objects */
terminate_login_session(login_session);
/* Serialize and unload reservation, rooms and customer objects */
terminate_management_session(hotel_session);
}

static void discard(LoginSession *login_session, HotelSession *hotel_session)
{
terminate_login_session(login_session);
discard_management_session(hotel_session);
}

int exit_menu(LoginSession *login_session, HotelSession *hotel_session)
{
while (1) {
display_menu(MENU_STATIC);
int choice = choices(MENU_CHOICES);
switch (choice) {
case 1:
save(login_session, hotel_session);
exit(0);
case 2:
case IO_STATUS_EXIT:
discard(login_session, hotel_session);
exit(0);
case 3:
case IO_STATUS_ESC:
return MENU_SIGNAL_CANCEL;
case IO_STATUS_UNDO:
continue;
}
}
}
6 changes: 6 additions & 0 deletions src/ui/menus/exit_menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <management.h>
#include <login.h>

int exit_menu(LoginSession *login_session, HotelSession *hotel_session);
2 changes: 1 addition & 1 deletion src/ui/menus/login.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "login.h"
#include "status.h"
#include "../status.h"
#include <libui/io.h>

#define MENU_STATIC\
Expand Down
4 changes: 0 additions & 4 deletions src/ui/menus/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"Reservation Report\n"\
"Sign Out\n"\
"Exit\n"\
"Exit Without Saving\n"


int main_menu(HotelSession *session)
{
Expand All @@ -34,8 +32,6 @@ int main_menu(HotelSession *session)
return MENU_SIGNAL_CANCEL;
if (choice == 11 || choice == IO_STATUS_EXIT)
return MENU_SIGNAL_EXIT;
if (choice == 12)
return MENU_SIGNAL_EXIT_ABRUPT;
return choice;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>

#include "status.h"
#include "../status.h"

#define MENU_OPTIONS \
"By Customer Name\n"\
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/reservation.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <libui/io.h>
#include <management.h>

#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"RESERVATION\n"\
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/reservation_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdio.h>
#include <libui/io.h>
#include "reservation_report.h"
#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"RESERVATION REPORT \n" \
Expand Down
2 changes: 1 addition & 1 deletion src/ui/menus/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <libui/io.h>
#include <libui/charcodes.h>

#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"Welcome to the hotel's reservation system.\n"\
Expand Down
3 changes: 0 additions & 3 deletions src/ui/menus/status.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/ui/menus/view_customer_details.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdio.h>
#include <management.h>

#include "status.h"
#include "../status.h"

#define MENU_STATIC \
"SEARCH CUSTOMER DETAILS\n"\
Expand Down
3 changes: 3 additions & 0 deletions src/ui/status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

typedef enum { MENU_SIGNAL_EXIT = -4, MENU_SIGNAL_CANCEL, MENU_SIGNAL_PROCEED, MENU_SIGNAL_EXIT_ABRUPT } MenuSignal;
23 changes: 12 additions & 11 deletions src/ui/ui.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include "menus/root.h"
#include "menus/login.h"
#include "menus/main.h"
#include "menus/availability.h"
#include "menus/reservation.h"
#include "menus/check_in.h"
#include "menus/cancel_reservation.h"
#include "menus/status.h"
#include "menus/view_customer_details.h"
#include "menus/query.h"
#include "menus/reservation_report.h"
#include <menus/root.h>
#include <menus/login.h>
#include <menus/main.h>
#include <menus/availability.h>
#include <menus/reservation.h>
#include <menus/check_in.h>
#include <menus/cancel_reservation.h>
#include <status.h>
#include <menus/view_customer_details.h>
#include <menus/query.h>
#include <menus/reservation_report.h>
#include <menus/exit_menu.h>

0 comments on commit 7ea8d4b

Please sign in to comment.