From 2c0ab40953997f7db10719f677e66f978de4f311 Mon Sep 17 00:00:00 2001 From: SterlingSunshine Date: Wed, 26 May 2021 23:50:18 -0700 Subject: [PATCH 1/2] Set up and laptop dying, sanity push --- main.py | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ed3f1a77..437e0180 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,132 @@ URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" -def main(): - print("WELCOME TO RETRO VIDEO STORE") +''' + ============================================= + HELPER PRINTS + ============================================= +''' + +def bar_break(): + print("\n==========================\n") + +def list_options_ee(): + options = { + "1" : "Add Video to Store Stock", + "2" : "Edit Video Info", + "3" : "Remove Video From Inventory", + "4" : "View Current Store Stock", + "5" : "View Video Info", + "6" : "Add New Customer", + "7" : "Edit Existing Customer", + "8" : "Delete Existing Customer", + "9" : "View Existing Customer Records", + "10" : "View All Existing Customers", + "11" : "Check Out", + "12" : "Check In" + } + + bar_break() + print("Here are your available options:\n") + for choice in options: + print(f"Option {choice}. {options[choice]}") + + bar_break() + + return options + +def list_options_cust(): + options = { + + } + +''' + ============================================= + ALL OPTION FUNCTIONS + ============================================= +''' + +def add_video(): + pass + +def edit_video(): + pass + +def remove_video(): + pass + +def view_video_stock(): + pass + +def view_single_video(): + pass + +def add_customer(): pass +def edit_customer(): + pass + +def delete_customer(): + pass + +def view_customer(): + pass + +def view_all_customers(): + pass + +def checking_out(): + pass + +def checking_in(): + pass + +''' + ============================================= + MAIN + ============================================= +''' + +def main(in_use=True, is_employee=False): + print("WELCOME TO RETRO VIDEO STORE") + + ee_id = input("Employee? Please enter your 4 digit id. Hit Enter to continue as a customer.\n") + if len(ee_id) == 4 and ee_id.isdigit(): + print(f"Welcome to work, Employee {ee_id}") + is_employee = True + options = list_options_ee() + + while is_employee and in_use: + func_call_dict = { + "1" : add_video, + "2" : edit_video, + "3" : remove_video, + "4" : view_video_stock, + "5" : view_single_video, + "6" : add_customer, + "7" : edit_customer, + "8" : delete_customer, + "9" : view_customer, + "10" : view_all_customers, + "11" : checking_out, + "12" : checking_in + } + + choice = None + while choice not in func_call_dict: + choice = input("What would you like to do? Q to quit.\n") + + if choice == "Q" or choice == 'q': + print("Thank you for visiting the Retro Video Store!") + bar_break() + return + else: + func_call_dict[choice]() + + while in_use: + pass + if __name__ == "__main__": main() \ No newline at end of file From de462e00efa54f0a1caa0822faa197af10e1058f Mon Sep 17 00:00:00 2001 From: SterlingSunshine Date: Fri, 28 May 2021 20:28:28 -0700 Subject: [PATCH 2/2] All required in and tested a bit --- main.py | 153 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 131 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 437e0180..09be8ac4 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,11 @@ +from flask import json import requests +from requests.api import request URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" + ''' ============================================= HELPER PRINTS @@ -41,48 +44,141 @@ def list_options_cust(): options = { } + pass ''' ============================================= - ALL OPTION FUNCTIONS + EMPLOYEE OPTION FUNCTIONS ============================================= ''' def add_video(): - pass + print("Enter video info below:") + request_body = {} + request_body["title"] = input("Title: ") + request_body["release_date"] = input("Release date: ") + request_body["total_inventory"] = input("Total inventory: ") + + response = requests.post(URL +"/videos", json=request_body) + print(json.dumps(response.json(), indent=1)) + return def edit_video(): - pass + print("Enter updated video info below:") + request_body = {} + video_id = input("Video ID: ") + request_body["title"] = input("Title: ") + request_body["release_date"] = input("Release date: ") + request_body["total_inventory"] = input("Total inventory: ") + + response = requests.put(URL +"/videos/" +video_id, json=request_body) + print(json.dumps(response.json(), indent=1)) + return def remove_video(): - pass + print("DELETE VIDEO - THIS ACTION CANNOT BE UNDONE") + if input("Are you sure? Y/N ") != "Y": + print("ACTION CANCELLED") + return + + video_id = input("Video ID: ") + response = requests.delete(URL +"/videos/" +video_id) + print(json.dumps(response.json(), indent=1)) + return def view_video_stock(): - pass + print("All Videos in Store Stock:") + response = requests.get(URL +"/videos") + print(json.dumps(response.json(), indent=2)) + return def view_single_video(): - pass + print("Video Info Request:") + video_id = input("Video ID: ") + response = requests.get(URL +"/videos/" +video_id) + print(json.dumps(response.json(), indent=1)) + return def add_customer(): - pass + print("Enter customer info below:") + request_body = {} + request_body["name"] = input("Name: ") + request_body["phone"] = input("Phone number: ") + request_body["postal_code"] = input("Postal code: ") + + response = requests.post(URL +"/customers", json=request_body) + print(json.dumps(response.json(), indent=1)) + return def edit_customer(): - pass + print("Enter updated customer info below:") + request_body = {} + customer_id = input("Customer ID: ") + request_body["name"] = input("Name: ") + request_body["phone"] = input("Phone number: ") + request_body["postal_code"] = input("Postal code: ") + + response = requests.put(URL +"/customers/" +customer_id, json=request_body) + print(json.dumps(response.json(), indent=1)) + return def delete_customer(): - pass + print("DELETE CUSTOMER - THIS ACTION CANNOT BE UNDONE") + if input("Are you sure? Y/N ") != "Y": + print("ACTION CANCELLED") + return + + customer_id = input("Customer ID: ") + response = requests.delete(URL +"/customers/" +customer_id) + print(json.dumps(response.json(), indent=1)) + return def view_customer(): - pass + print("Customer Info Request:") + customer_id = input("Customer ID: ") + response = requests.get(URL +"/customers/" +customer_id) + print(json.dumps(response.json(), indent=1)) + return def view_all_customers(): - pass + print("All Active Customer Accounts:") + response = requests.get(URL +"/customers") + print(json.dumps(response.json(), indent=2)) + return def checking_out(): - pass + print("Check Out a Video:") + request_body = {} + request_body["customer_id"] = int(input("Customer ID: ")) + request_body["video_id"] = int(input("Video ID: ")) + + response = requests.post(URL +"/rentals/check-out", json=request_body) + print(json.dumps(response.json(), indent=1)) + return def checking_in(): - pass + print("Check In a Video:") + request_body = {} + request_body["customer_id"] = int(input("Customer ID: ")) + request_body["video_id"] = int(input("Video ID: ")) + + response = requests.post(URL +"/rentals/check-in", json=request_body) + print(json.dumps(response.json(), indent=1)) + return + +''' + ============================================= + CUSTOMER OPTION FUNCTIONS + ============================================= +''' + +def find_videos_by(): + print("I'm sorry, that feature is not yet available in your area") + return + +def check_current_rentals(): + print("I'm sorry, that feature is not yet available in your area") + return ''' ============================================= @@ -97,7 +193,7 @@ def main(in_use=True, is_employee=False): if len(ee_id) == 4 and ee_id.isdigit(): print(f"Welcome to work, Employee {ee_id}") is_employee = True - options = list_options_ee() + list_options_ee() while is_employee and in_use: func_call_dict = { @@ -119,16 +215,29 @@ def main(in_use=True, is_employee=False): while choice not in func_call_dict: choice = input("What would you like to do? Q to quit.\n") - if choice == "Q" or choice == 'q': - print("Thank you for visiting the Retro Video Store!") - bar_break() - return - else: - func_call_dict[choice]() + if choice == "Q" or choice == 'q': + print(f"Goodbye Retro Video Store Employee {ee_id}!") + bar_break() + return + + func_call_dict[choice]() + bar_break() while in_use: - pass + func_call_dict = { + "1" : find_videos_by, + "2" : check_current_rentals + } + + choice = None + while choice not in func_call_dict: + choice = input("What would you like to do? Q to quit.\n") + + if choice == "Q" or choice == 'q': + print(f"Goodbye Retro Video Store Employee {ee_id}!") + bar_break() + return if __name__ == "__main__": - main() \ No newline at end of file + main()