示例#1
0
def delete_customer(customer_id):
    """Deletes customer from database"""
    try:
        the_customer = Customer.get(Customer.customer_id == customer_id)
        the_customer.delete_instance()

    except peewee.DoesNotExist:
        LOGGER.warning(f'Customer {customer_id} is not in the database!')
        raise
示例#2
0
def update_customer_credit(customer_id, credit_limit):
    """Searches for existing customer, updates the credit limit, or raises ValueError if
    customer not found"""
    try:
        update_credit = Customer.get(Customer.customer_id == customer_id)
        update_credit.credit_limit = credit_limit
        update_credit.save()
        LOGGER.info('Credit limit successfully updated and saved')

    except peewee.DoesNotExist:
        LOGGER.info('Error with updating credit limit')
        raise
示例#3
0
def search_customer(customer_id):
    """Searches for customer by ID, returns a dictionary object with name, last name, email address,
     and phone number OR an empty dict if no customer found"""
    try:
        the_customer = Customer.get(Customer.customer_id == customer_id)
        return {
            'Name': the_customer.first_name,
            'Last Name': the_customer.last_name,
            'Email': the_customer.email,
            'Phone Number': the_customer.phone
        }

    except peewee.DoesNotExist:
        LOGGER.warning(f'Customer {customer_id} is not in the database!')
        # Return an empty dictionary
        return {}