-
Notifications
You must be signed in to change notification settings - Fork 70
Paper--Andrea Palacios #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
|
|
||
| from video_store import VideoStore | ||
|
|
||
| URL = "http://127.0.0.1:5000" | ||
| BACKUP_URL = "https://retro-video-store-api.herokuapp.com" | ||
|
|
||
|
|
||
| video_store= VideoStore(url=URL) | ||
|
|
||
| def print_stars(): | ||
| print("\n*********************************\n") | ||
|
|
||
| def to_int(input): | ||
| if input.isnumeric(): | ||
| input=int(input) | ||
| else: | ||
| print("Please enter valid id number: ") | ||
|
|
||
|
|
||
| def get_vid(): | ||
| print("Great! Let's look-up a video!") | ||
| video_id= input("Please enter the video id: ") | ||
| to_int(video_id) | ||
|
|
||
| video_store.get_video(video_id) | ||
|
|
||
|
|
||
| def add_video(): | ||
| print("Let's add a New Video!") | ||
| video_id= input("Please input the video id: ") | ||
| to_int(video_id) | ||
|
|
||
| title=input("Please enter a title: ") | ||
| release_date=input("Please enter a release date: ") | ||
| total_inventory=input("Please enter the total inventory: ") | ||
|
|
||
| response= video_store.create_video( | ||
| title=title, | ||
| release_date=release_date, | ||
| total_inventory=total_inventory) | ||
|
|
||
| print("New Video: ", response["video"]) | ||
|
|
||
| def del_vid(): | ||
| print("Let's Delete a video!") | ||
| video_id= input("Please input the video id: ") | ||
| to_int(video_id) | ||
| video_store.delete_video() | ||
|
|
||
| print_stars() | ||
| print("Video has been deleted") | ||
|
|
||
|
|
||
| def update_vid(): | ||
| print("Let's update a Video!") | ||
| video_id= input("Please input the video id: ") | ||
| to_int(video_id) | ||
|
|
||
| title=input("Please enter the updated or current title: ") | ||
| release_date=input("Please enter the updated or current release date: ") | ||
| total_inventory=input("Please enter the total inventory: ") | ||
|
|
||
| response= video_store.update_video( | ||
| title=title, | ||
| release_date=release_date, | ||
| total_inventory=total_inventory) | ||
|
|
||
| print("New Video: ", response["video"]) | ||
|
|
||
|
|
||
| def all_videos(): | ||
| print_stars() | ||
| for vid in video_store.list_videos(): | ||
| print(vid) | ||
|
|
||
|
|
||
| def get_customer(): | ||
| print("Let's pull up a customer account!") | ||
| customer_id= input("Please enter the customer id:") | ||
| to_int(customer_id) | ||
|
|
||
| video_store.get_customer(customer_id) | ||
|
|
||
|
|
||
| def del_customer(): | ||
| print("Let's delete a customer!") | ||
| customer_id=input("Please enter customer id: ") | ||
| to_int(customer_id) | ||
|
|
||
| response=video_store.delete_customer(customer_id) | ||
| print(response) | ||
|
|
||
|
|
||
| def update_customer(): | ||
| print("Great! Let's update a customer!") | ||
| customer_id="Please input customer id: " | ||
| to_int(customer_id) | ||
|
|
||
| name=input("Please enter the updated or current name: ") | ||
| postal_code=input("Please enter the updated or current postal code: ") | ||
| phone = input("Please enter the updated or current phone number: ") | ||
| response = video_store.update_customer(name = name,postal_code = postal_code,phone = phone) | ||
|
|
||
| print_stars() | ||
| print("Updated customer:", response["customer"]) | ||
|
|
||
|
|
||
| def all_customers(): | ||
| for cust in video_store.list_customers(): | ||
| print(cust) | ||
|
|
||
|
|
||
| def check_in_rental(): | ||
| print("Great! Let's check-in a video") | ||
|
|
||
| customer_id=("Please enter customer id: ") | ||
| to_int(customer_id) | ||
| video_id= input("Please enter the video id: ") | ||
| to_int(video_id) | ||
|
|
||
| response = video_store.check_in(customer_id=customer_id, video_id=video_id) | ||
|
|
||
| print_stars() | ||
| print("Video Rental:", response["rental"]) | ||
|
|
||
|
|
||
| def check_out_rental(): | ||
| print("Great! Let's check-out a video") | ||
|
|
||
| customer_id=("Please enter customer id: ") | ||
| to_int(customer_id) | ||
| video_id= input("Please enter the video id: ") | ||
| to_int(video_id) | ||
|
|
||
| response = video_store.check_out(customer_id=customer_id, video_id=video_id) | ||
|
|
||
| print_stars() | ||
| print("Video Rental:", response["rental"]) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| from commands import * | ||
| from video_store import VideoStore | ||
| from main import video_store | ||
|
|
||
|
|
||
| # URL = "http://127.0.0.1:5000" | ||
| # BACKUP_URL = "https://retro-video-store-api.herokuapp.com" | ||
|
|
||
| # video_store=VideoStore(url=URL) | ||
|
|
||
|
|
||
| def print_stars(): | ||
| print("\n*********************************\n") | ||
|
|
||
|
|
||
| #----MAIN MENU-----# | ||
| def main_menu(): | ||
| main_menu_options = { | ||
|
|
||
| "1.":"Manage Customer Records", | ||
| "2.":"Manage Video Records", | ||
| "3.":"Check-in Video", | ||
| "4.":"Check-out Video", | ||
| "5.": "All Done? Quit!" | ||
| } | ||
| print_stars() | ||
| print("Welcome to the Main Menu!") | ||
| print("Please pick which action you would like to perform") | ||
| print_stars() | ||
|
|
||
| for option in main_menu_options: | ||
| print(f"{option} {main_menu_options[option]}") | ||
|
|
||
| print_stars() | ||
|
|
||
| return main_menu_options | ||
|
|
||
| def make_main_choice(main_menu_options): | ||
| valid_choices = main_menu_options.keys() | ||
| choice = None | ||
|
|
||
| while choice not in valid_choices: | ||
| print("What would you like to do?") | ||
| choice = input("Make your selection using the option numbers: ") | ||
| return choice | ||
|
|
||
|
|
||
| #----CUSTOMER MENU----# | ||
| def customer_menu(): | ||
| customer_menu_options={ | ||
| "1.": "Get all Customers", | ||
| "2.": "Look-up a Customer", | ||
| "3.": "Add a Customer", | ||
| "4.": "Update a Customer", | ||
| "5.": "Delete a Customer", | ||
| "6.": "Go back to Main Menu"} | ||
|
Comment on lines
+50
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setup is causing a bug in the make_customer_choice function. The keys here are the numbers and a '.' so on line 71 the valid keys are ['1.', '2.', '3.', '4.', '5.', '6.']. If a user enters a number in the while loop starting on line 74, the test fails and they will stay in the while loop. The if/elif structure compares against '1', '2', etc, which means that if the user does enter a valid key, all of the tests fail and the function returns. |
||
|
|
||
| print_stars() | ||
| print("Welcome to the Customer Menu!") | ||
| print("Please pick which action you would like to perform") | ||
| print_stars() | ||
|
|
||
|
|
||
| for option in customer_menu_options: | ||
| print(f"{option} {customer_menu_options[option]}") | ||
| print_stars() | ||
|
|
||
| return customer_menu_options | ||
|
|
||
| def make_customer_choice(customer_menu_options): | ||
| valid_choices = customer_menu_options.keys() | ||
| choice = None | ||
|
|
||
| while choice not in valid_choices: | ||
| print("What would you like to do? Select 6 to go back to the main menu") | ||
| choice = input("Make your selection using a valid option number: ") | ||
|
|
||
| if choice =='1': | ||
| video_store.list_customers() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very close to working: list_customers makes the API request correctly, but nothing is done with the data that is returned. Adding a print statement here ( |
||
| elif choice=='2':#getone | ||
| id=input("Please input customer id: ") | ||
| to_int(id) | ||
| video_store.get_customer(id) | ||
| elif choice=='3':#add | ||
| print("Let's Create a Customer Account!") | ||
| name = input("Please input customer name: ") | ||
| postal_code=input("Please enter customer postal_code: ") | ||
| phone = input("Please enter customer phone number: ") | ||
| response = video_store.create_customer(name=name, postal_code=postal_code, phone = phone) | ||
| print(response) | ||
| elif choice=='4':# | ||
| id= input("Please input customer id: ") | ||
| to_int(id) | ||
| title= input("Please input video title: ") | ||
| release_date=input("Please enter video release date: ") | ||
| total_inventory=input("Please enter total_inventory: ") | ||
| response= video_store.update_video(id=id,title=title, | ||
| release_date=release_date, total_inventory=total_inventory) | ||
| print(response) | ||
| elif choice=='5':#delete | ||
| id=input("Please enter video id:") | ||
| to_int(id) | ||
| response = video_store.delete_customer(id=id) | ||
| print(response) | ||
| elif choice == '6':#main menu | ||
| options= main_menu() | ||
| choice = make_main_choice(options) | ||
| return choice | ||
|
|
||
|
|
||
|
|
||
|
|
||
| #---VIDEO MENU---# | ||
| def video_menu(): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting these into two menus is a great idea! This function is almost identical to customer_menu. When writing pieces of code like this that are almost the same, I recommend trying to find a way to make it into one multi-purpose helper function, perhaps a function that takes the menu item name as an argument. |
||
| video_menu_options={ | ||
| "1.": "Get All Videos", | ||
| "2.": "Look-up a Video", | ||
| "3.": "Add a Video", | ||
| "4.": "Update a Video", | ||
| "5.": "Delete a Video", | ||
| "6.": "Go back to Main Menu"} | ||
|
|
||
| print_stars() | ||
| print("Welcome to the Video Menu!") | ||
| print("Please pick which action you would like to perform") | ||
| print_stars() | ||
|
|
||
| for option in video_menu_options: | ||
| print(f"{option} {video_menu_options[option]}") | ||
| print_stars() | ||
|
|
||
| return video_menu_options | ||
|
|
||
| def make_video_choice(video_menu_options): | ||
|
|
||
| valid_choices = video_menu_options.keys() | ||
| choice = None | ||
|
|
||
| while choice not in valid_choices: | ||
| print("What would you like to do?") | ||
| choice = input("Make your selection using a valid option number: ") | ||
|
|
||
| return choice | ||
|
|
||
| if choice =='1': | ||
| video_store.all_videos() | ||
| elif choice=='2':#getone | ||
| id=input("Please input video id: ") | ||
| to_int(id) | ||
| video_store.get_video(id) | ||
| elif choice=='3':#add | ||
| title= input("Please input video title: ") | ||
| release_date=input("Please enter video release date: ") | ||
| total_inventory=input("Please enter total_inventory: ") | ||
| response=video_store.create_video(title=title, | ||
| release_date=release_date, total_inventory=total_inventory) | ||
| print(response) | ||
| elif choice=='4':#update | ||
| id= input("Please input video id: ") | ||
| to_int(id) | ||
| title= input("Please input video title: ") | ||
| release_date=input("Please enter video release date: ") | ||
| total_inventory=input("Please enter total_inventory: ") | ||
| response= video_store.update_video(id=id,title=title, | ||
| release_date=release_date, total_inventory=total_inventory) | ||
| print(response) | ||
| elif choice=='5':#delete | ||
| id=input("Please enter video id") | ||
| to_int(id) | ||
| response=video_store.delete_video(id=id) | ||
| print(response) | ||
| elif choice == '6':#main menu | ||
| options= main_menu() | ||
| choice = make_main_choice(options) | ||
| return choice | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tab level here caused some issues. Because everything starting at line 20 is tabbed in, everything is part of the to_int function. All of these functions are inner functions, and only exist inside of to_int. It looks like there is functionality here that is missing from menus (printing the result of the requests).