Archived
completed chapter 6
This commit is contained in:
+10
-3
@@ -1,7 +1,7 @@
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from views.customer_requests import get_all_customers, get_single_customer, create_customer, delete_customer
|
||||
from views.employees_requests import create_employee, get_all_employees, get_single_employee, delete_employee
|
||||
from views.location_requests import create_location, get_all_locations, get_single_location, delete_location
|
||||
from views.customer_requests import get_all_customers, get_single_customer, create_customer, delete_customer, update_customer
|
||||
from views.employees_requests import create_employee, get_all_employees, get_single_employee, delete_employee, update_employee
|
||||
from views.location_requests import create_location, get_all_locations, get_single_location, delete_location, update_location
|
||||
from views.animal_requests import create_animal, get_all_animals, get_single_animal, delete_animal, update_animal
|
||||
import json
|
||||
|
||||
@@ -156,6 +156,13 @@ class HandleRequests(BaseHTTPRequestHandler):
|
||||
# Delete a single animal from the list
|
||||
if resource == "animals":
|
||||
update_animal(id, post_body)
|
||||
if resource == "customers":
|
||||
update_customer(id, post_body)
|
||||
if resource == "employees":
|
||||
update_employee(id, post_body)
|
||||
if resource == "locations":
|
||||
update_location(id, post_body)
|
||||
|
||||
|
||||
# Encode the new animal and send in response
|
||||
self.wfile.write("".encode())
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
|
||||
from .employees_requests import get_all_employees, get_single_employee, create_employee, delete_employee
|
||||
from .location_requests import get_all_locations, get_single_location, create_location, delete_location
|
||||
from .employees_requests import get_all_employees, get_single_employee, create_employee, delete_employee, update_employee
|
||||
from .location_requests import get_all_locations, get_single_location, create_location, delete_location, update_location
|
||||
from .animal_requests import create_animal, delete_animal, get_all_animals, get_single_animal, update_animal
|
||||
from .customer_requests import get_all_customers, get_single_customer, create_customer, delete_customer
|
||||
from .customer_requests import get_all_customers, get_single_customer, create_customer, delete_customer, update_customer
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ def delete_animal(id):
|
||||
if animal_index >= 0:
|
||||
ANIMALS.pop(animal_index)
|
||||
|
||||
|
||||
def update_animal(id, new_animal):
|
||||
# Iterate the ANIMALS list, but use enumerate() so that
|
||||
# you can access the index value of each item.
|
||||
@@ -84,3 +83,6 @@ def update_animal(id, new_animal):
|
||||
# Found the animal. Update the value.
|
||||
ANIMALS[index] = new_animal
|
||||
break
|
||||
|
||||
|
||||
|
||||
@@ -88,3 +88,12 @@ def delete_customer(id):
|
||||
if customer_index >= 0:
|
||||
CUSTOMERS.pop(customer_index)
|
||||
|
||||
def update_customer(id, new_customer):
|
||||
# Iterate the CUSTOMERS list, but use enumerate() so that
|
||||
# you can access the index value of each item.
|
||||
for index, customer in enumerate(CUSTOMERS):
|
||||
if customer["id"] == id:
|
||||
# Found the customer. Update the value.
|
||||
CUSTOMERS[index] = new_customer
|
||||
break
|
||||
|
||||
|
||||
+27
-26
@@ -2,80 +2,71 @@ EMPLOYEES = [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Jessica Younker",
|
||||
"email": "jessica@younker.com",
|
||||
"employee": True
|
||||
"email": "jessica@younker.com"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Jordan Nelson",
|
||||
"email": "jordan@nelson.com",
|
||||
"employee": True
|
||||
"email": "jordan@nelson.com"
|
||||
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Zoe LeBlanc",
|
||||
"email": "zoe@leblanc.com",
|
||||
"employee": True
|
||||
"email": "zoe@leblanc.com"
|
||||
|
||||
},
|
||||
{
|
||||
"name": "Meg Ducharme",
|
||||
"email": "meg@ducharme.com",
|
||||
"id": 4,
|
||||
"employee": True
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"name": "Hannah Hall",
|
||||
"email": "hannah@hall.com",
|
||||
"id": 5,
|
||||
"employee": True
|
||||
"id": 5
|
||||
|
||||
},
|
||||
{
|
||||
"name": "Emily Lemmon",
|
||||
"email": "emily@lemmon.com",
|
||||
"id": 6,
|
||||
"employee": True
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"name": "Jordan Castelloe",
|
||||
"email": "jordan@castelloe.com",
|
||||
"id": 7,
|
||||
"employee": True
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"name": "Leah Gwin",
|
||||
"email": "leah@gwin.com",
|
||||
"id": 8,
|
||||
"employee": True
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"name": "Caitlin Stein",
|
||||
"email": "caitlin@stein.com",
|
||||
"id": 9,
|
||||
"employee": True
|
||||
"id": 9
|
||||
},
|
||||
{
|
||||
"name": "Greg Korte",
|
||||
"email": "greg@korte.com",
|
||||
"id": 10,
|
||||
"employee": True
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"name": "Charisse Lambert",
|
||||
"email": "charisse@lambert.com",
|
||||
"id": 11,
|
||||
"employee": True
|
||||
"id": 11
|
||||
},
|
||||
{
|
||||
"name": "Madi Peper",
|
||||
"email": "madi@peper.com",
|
||||
"id": 12,
|
||||
"employee": True
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"name": "Jenna Solis",
|
||||
"email": "jenna@solis.com",
|
||||
"id": 14,
|
||||
"employee": True
|
||||
"id": 14
|
||||
},
|
||||
|
||||
]
|
||||
@@ -122,3 +113,13 @@ def delete_employee(id):
|
||||
# If the employee was found, use pop(int) to remove it from list
|
||||
if employee_index >= 0:
|
||||
EMPLOYEES.pop(employee_index)
|
||||
|
||||
|
||||
def update_employee(id, new_employee):
|
||||
# Iterate the EMPLOYEES list, but use enumerate() so that
|
||||
# you can access the index value of each item.
|
||||
for index, employee in enumerate(EMPLOYEES):
|
||||
if employee["id"] == id:
|
||||
# Found the employee. Update the value.
|
||||
EMPLOYEES[index] = new_employee
|
||||
break
|
||||
|
||||
@@ -53,4 +53,13 @@ def delete_location(id):
|
||||
# If the location was found, use pop(int) to remove it from list
|
||||
if location_index >= 0:
|
||||
LOCATIONS.pop(location_index)
|
||||
|
||||
def update_location(id, new_location):
|
||||
# Iterate the LOCATIONS list, but use enumerate() so that
|
||||
# you can access the index value of each item.
|
||||
for index, location in enumerate(LOCATIONS):
|
||||
if location["id"] == id:
|
||||
# Found the location. Update the value.
|
||||
LOCATIONS[index] = new_location
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user