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