From 17040c282ff95964a1ef392477ee80f0e6950df2 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Wed, 12 Jan 2022 15:19:02 -0600 Subject: [PATCH] save completed ch. 3 work (not tested) --- request_handler.py | 20 ++++++++ views/customer_requests.py | 58 +++++++++++++++++++++++ views/employees_requests.py | 94 +++++++++++++++++++++++++++++++++++++ views/location_requests.py | 24 ++++++++++ 4 files changed, 196 insertions(+) create mode 100644 views/customer_requests.py diff --git a/request_handler.py b/request_handler.py index 76e3fdb..5262ef6 100644 --- a/request_handler.py +++ b/request_handler.py @@ -1,6 +1,8 @@ from http.server import BaseHTTPRequestHandler, HTTPServer from views import get_all_animals, get_single_animal from http.server import BaseHTTPRequestHandler, HTTPServer +from views.employees_requests import get_all_employees, get_single_employee +from views.location_requests import get_all_locations, get_single_location @@ -77,6 +79,24 @@ class HandleRequests(BaseHTTPRequestHandler): response = f"{get_all_animals()}" self.wfile.write(response.encode()) + + if resource == "locations": + if id is not None: + response = f"{get_single_location(id)}" + + else: + response = f"{get_all_locations()}" + + self.wfile.write(response.encode()) + + if resource == "employees": + if id is not None: + response = f"{get_single_employee(id)}" + + else: + response = f"{get_all_employees()}" + + self.wfile.write(response.encode()) # Here's a method on the class that overrides the parent's method. # It handles any POST request. diff --git a/views/customer_requests.py b/views/customer_requests.py new file mode 100644 index 0000000..ff0c418 --- /dev/null +++ b/views/customer_requests.py @@ -0,0 +1,58 @@ +CUSTOMERS = [ + { + "id": 1, + "name": "Ryan Tanay", + "email": "ryan@tanay.com", + "employee": false + }, + { + "id": 2, + "name": "Emma Beaton", + "email": "emma@beaton.com", + "employee": false + }, + { + "id": 3, + "name": "Dani Adkins", + "email": "dani.adkins.com", + "employee": false + }, + { + "id": 4, + "name": "Adam Oswalt", + "email": "adam@oswalt.com", + "employee": false + }, + { + "id": 5, + "name": "Fletcher Bangs", + "email": "flangs@bangs.com", + "employee": false + }, + { + "id": 6, + "name": "Angela Lee", + "email": "lee@lee.com", + "employee": false + }, + { + "name": "mike mike", + "email": "m@m.com", + "employee": false, + "id": 7 + }, + + ] + +def get_all_customers(): + return CUSTOMERS + +def get_single_customer(): + requested_customer = None + + + for customer in CUSTOMERS: + if customer["id"] == id: + requested_customer = customer + + return requested_customer diff --git a/views/employees_requests.py b/views/employees_requests.py index e69de29..80c4632 100644 --- a/views/employees_requests.py +++ b/views/employees_requests.py @@ -0,0 +1,94 @@ +EMPLOYEES = [ + { + "id": 1, + "name": "Jessica Younker", + "email": "jessica@younker.com", + "employee": true + }, + { + "id": 2, + "name": "Jordan Nelson", + "email": "jordan@nelson.com", + "employee": true + }, + { + "id": 3, + "name": "Zoe LeBlanc", + "email": "zoe@leblanc.com", + "employee": true + }, + { + "name": "Meg Ducharme", + "email": "meg@ducharme.com", + "id": 4, + "employee": true + }, + { + "name": "Hannah Hall", + "email": "hannah@hall.com", + "id": 5, + "employee": true + }, + { + "name": "Emily Lemmon", + "email": "emily@lemmon.com", + "id": 6, + "employee": true + }, + { + "name": "Jordan Castelloe", + "email": "jordan@castelloe.com", + "id": 7, + "employee": true + }, + { + "name": "Leah Gwin", + "email": "leah@gwin.com", + "id": 8, + "employee": true + }, + { + "name": "Caitlin Stein", + "email": "caitlin@stein.com", + "id": 9, + "employee": true + }, + { + "name": "Greg Korte", + "email": "greg@korte.com", + "id": 10, + "employee": true + }, + { + "name": "Charisse Lambert", + "email": "charisse@lambert.com", + "id": 11, + "employee": true + }, + { + "name": "Madi Peper", + "email": "madi@peper.com", + "id": 12, + "employee": true + }, + { + "name": "Jenna Solis", + "email": "jenna@solis.com", + "id": 14, + "employee": true + }, + +] + +def get_all_employees(): + return EMPLOYEES + +def get_single_employee(): + requested_employee = None + + + for employee in EMPLOYEES: + if EMPLOYEES["id"] == id: + requested_EMPLOYEE = employee + + return requested_employee \ No newline at end of file diff --git a/views/location_requests.py b/views/location_requests.py index e69de29..a14366c 100644 --- a/views/location_requests.py +++ b/views/location_requests.py @@ -0,0 +1,24 @@ +LOCATIONS = [ + { + "id": 1, + "name": "Nashville North" + }, + { + "id": 2, + "name": "Nashville South" + } + , +] + +def get_all_locations(): + return LOCATIONS + +def get_single_location(): + requested_location = None + + + for location in LOCATIONS: + if location["id"] == id: + requested_location = location + + return requested_location