def delete_customer(customer_id): """use customer ID to find and delete a customer from the database""" try: remove_customer = Customer.get(Customer.customer_id == customer_id) remove_customer.delete_instance() logging.info(f"Customer {customer_id} was found, deleting from the database") except DoesNotExist: logging.info(f"Customer with id {customer_id} does not exist") logging.info(DoesNotExist) raise DoesNotExist
def update_customer_credit(customer_id, credit_limit): """Use customer ID to update the customer credit limit record""" try: update_customer = Customer.get(Customer.customer_id == customer_id) update_customer.credit_limit = credit_limit update_customer.save() logging.info(f"Customer with id of {customer_id} has had their credit limit changed to {credit_limit}") except DoesNotExist: logging.info(f"Customer with id {customer_id} does not exist") logging.info(DoesNotExist) raise DoesNotExist
def search_customer(customer_id): """use customer ID to return a dictionary object with the first name, last name, email address and phone number of that customer""" try: customer_found = Customer.get(Customer.customer_id == customer_id) logging.info(f"Customer found with id of {customer_id}") return {"first_name": customer_found.first_name, "last_name": customer_found.last_name, "email_address": customer_found.email_address, "phone_number": customer_found.phone_number} except DoesNotExist: logging.info(f"Customer id {customer_id} does not exist") logging.info(DoesNotExist) return {}