Skip to content

Commit

Permalink
feat: add return main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Thungghuan committed Oct 8, 2022
1 parent 6d113d0 commit 8342342
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 25 additions & 3 deletions cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def run(self):
while self.state != CheckState.QUIT:
match self.state:
case CheckState.LIST:
self.list_tickets()
is_quit = self.list_tickets()

if is_quit:
return 1

case CheckState.DETAIL:
self.get_ticket_detail()
Expand All @@ -34,6 +37,8 @@ def run(self):
case CheckState.DELETE:
self.delete_ticket()

return 0

def change_state(self, state: CheckState):
self.state = state

Expand All @@ -52,18 +57,35 @@ def list_tickets(self):
)

if len(ticket_choices) > 0:

ticket_choices.append(
{
"name": "{}. 返回主菜单".format(len(tickets) + 1),
"value": -1,
}
)

choice = questionary.select(
"请选择班次:",
choices=ticket_choices,
).ask()

self.ticket = tickets[choice]
self.change_state(CheckState.DETAIL)
if choice == -1:
self.change_state(CheckState.QUIT)
return True

else:
self.ticket = tickets[choice]
self.change_state(CheckState.DETAIL)

return False

else:
print("没有找到预约的校巴哦")
self.change_state(CheckState.QUIT)

return False

def get_ticket_detail(self):
result = self.bus.ticket_detail(self.ticket["id"])["data"]

Expand Down
8 changes: 6 additions & 2 deletions cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ def reserve_bus(self):

def check_reserve(self):
check_reserve_menu = CheckReserveMenu(self.bus)
check_reserve_menu.run()
result = check_reserve_menu.run()

self.back_main_menu()
if result == 1:
self.change_state(MenuState.START)

else:
self.back_main_menu()

def quit(self):
print("88")
Expand Down

0 comments on commit 8342342

Please sign in to comment.