diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..fad6dea5 Binary files /dev/null and b/.DS_Store differ diff --git a/__pycache__/commands.cpython-39.pyc b/__pycache__/commands.cpython-39.pyc new file mode 100644 index 00000000..017111d9 Binary files /dev/null and b/__pycache__/commands.cpython-39.pyc differ diff --git a/__pycache__/customer.cpython-39.pyc b/__pycache__/customer.cpython-39.pyc new file mode 100644 index 00000000..09bb5921 Binary files /dev/null and b/__pycache__/customer.cpython-39.pyc differ diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc new file mode 100644 index 00000000..eb50b61e Binary files /dev/null and b/__pycache__/main.cpython-39.pyc differ diff --git a/__pycache__/menus.cpython-39.pyc b/__pycache__/menus.cpython-39.pyc new file mode 100644 index 00000000..75d15792 Binary files /dev/null and b/__pycache__/menus.cpython-39.pyc differ diff --git a/__pycache__/rental.cpython-39.pyc b/__pycache__/rental.cpython-39.pyc new file mode 100644 index 00000000..aa45511c Binary files /dev/null and b/__pycache__/rental.cpython-39.pyc differ diff --git a/__pycache__/video.cpython-39.pyc b/__pycache__/video.cpython-39.pyc new file mode 100644 index 00000000..705d2f70 Binary files /dev/null and b/__pycache__/video.cpython-39.pyc differ diff --git a/__pycache__/video_store.cpython-39.pyc b/__pycache__/video_store.cpython-39.pyc new file mode 100644 index 00000000..1017cd0c Binary files /dev/null and b/__pycache__/video_store.cpython-39.pyc differ diff --git a/commands.py b/commands.py new file mode 100644 index 00000000..67975d46 --- /dev/null +++ b/commands.py @@ -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"]) + + + diff --git a/main.py b/main.py index ed3f1a77..42a489ca 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,47 @@ -import requests + +from video_store import VideoStore +from menus import * +from commands import check_out_rental, check_in_rental + URL = "http://127.0.0.1:5000" BACKUP_URL = "https://retro-video-store-api.herokuapp.com" -def main(): + +#video_store=VideoStore(url=BACKUP_URL) + + +def main(play=True): + video_store=VideoStore(url=BACKUP_URL) + print("WELCOME TO RETRO VIDEO STORE") - pass + + while play==True: + options=main_menu() + choice = make_main_choice(options) + if choice =='1': + options=customer_menu() + choice=make_customer_choice(options) + + elif choice=='2': + options=video_menu() + choice=make_video_choice(options) #put in video_menu? + + elif choice=='3': + check_out_rental() + + + elif choice=='4': + check_in_rental() + + + elif choice=='5': + play==False + print("\n See you later!") + + print_stars() + + if __name__ == "__main__": diff --git a/menus.py b/menus.py new file mode 100644 index 00000000..8b694c50 --- /dev/null +++ b/menus.py @@ -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"} + + 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() + 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(): + 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 + + diff --git a/video_store.py b/video_store.py new file mode 100644 index 00000000..024b8c1e --- /dev/null +++ b/video_store.py @@ -0,0 +1,95 @@ +import requests + + +class VideoStore: + def __init__(self, url="http://localhost:5000"): + self.url = url + + + def create_customer(self, name=None, postal_code=None, phone=None): + form_data = { + "name": name, + "postal_code": postal_code, + "phone": phone} + + response = requests.post(self.url+"/customers",json=form_data) + return response.json() + + def update_customer(self,name=None,postal_code=None, phone=None): + form_data = { + "name": name, + "postal_code": postal_code, + "phone": phone} + + response = requests.put(self.url+f"/customers/{id}",json=form_data) + return response.json() + + def list_customers(self): + response = requests.get(self.url+"/customers") + return response.json() + + def get_customer(self, id): + response = requests.get(self.url+f"/customers/{id}") + return response.json() + + + def delete_customer(self, id): + response = requests.delete(self.url+f"/customers/{id}") + return response.json() + + + def create_video(self,title=None, release_date=None,total_inventory=None): + form_data = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory} + + response = requests.post(self.url+"/videos",json=form_data) + return response.json() + + + def update_video(self,title=None,release_date=None, total_inventory=None): + form_data = { + "title": title, + "release_date": release_date, + "total_inventory": total_inventory} + #Available inventory? + response = requests.put(self.url+f"/videos/{id}",json= form_data) + return response.json() + + + def get_video(self, id=None): + response = requests.get(self.url+f"/videos/{id}") + return response.json() + + + def list_videos(self): + response = requests.get(self.url+"/videos") + print(response) + return response.json() + + + def delete_video(self, id=None): + response = requests.delete(self.url+f"/videos/{id}") + return response.json() + + + def check_in(self, customer_id=None, video_id=None): + form_data = { + "customer_id" : customer_id, + "video_id" : video_id} + #patch? + response = requests.patch(self.url+f"/rentals/check-in", json=form_data ) + return response.json() + + + def check_out(self, customer_id=None, video_id=None): + form_data = { + "customer_id" : customer_id, + "video_id" : video_id} + + response = requests.patch(self.url+f"/rentals/check-out",json=form_data ) + return response.json() + + +