Archived
save completed ch. 3 work (not tested)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user