yael1019 / phase-4-flask-practice-bank-accounts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask Practice - Bank Accounts

This application is being built to track banks, customers, and the accounts between them.

Getting Started

Fork and clone this repo. Use pipenv install and pipenv shell to begin. Be sure to cd server.

There are no tests so be sure to use the flask shell and Postman to be certain everything's working correctly!

Models

You have three models:

Bank

  • name (string): Cannot be null, must be unique

Customer

  • first_name (string): Cannot be null

  • last_name (string): Cannot be null

Account

  • balance (integer): Cannot be null, cannot be less than 0

  • account_type (string): Cannot be null

Relationships

This is a many-to-many relationship.

  • A bank has many accounts and an account belongs to a bank.

  • A customer has many accounts and an account belongs to a customer.

  • A bank has many customers and a customer has many banks through accounts.

Bank --< Account >-- Customer

The foreign keys aren't specified so you'll have to determine where they go.

Seeding

You can either use the seed.py to create your seeds or you can seed manually with flask shell.

Routes

Build out these routes:

Customer

GET /customers

Returns a list of all customers formatted like so:

[
    {
        "id": 1,
        "first_name": "Chett",
        "last_name": "Tiller"
    },
    {
        "id": 2,
        "first_name": "Charlie",
        "last_name": "Kozey"
    }
]

GET /customers/:id

Returns a customer with the matching id. If there is no customer, returns a message that the customer could not be found along with a 404.

Format your customer object like so:

    {
        "id": 1,
        "first_name": "Chett",
        "last_name": "Tiller",
        "accounts": [
            {
                "id": 1,
                "balance": 100,
                "account_type": "checking",
                "customer_name": "Chett Tiller",
                "bank_name": "Crown Royale"
            },
            {
                "id": 2,
                "balance": 30,
                "account_type": "savings",
                "customer_name": "Chett Tiller",
                "bank_name": "Royal Raccoon Bank"
            }
        ]
    }

Hint: You'll need to find a way to include the customer accounts in this route. This may involve a method similar to_dict()

DELETE /customer/:id

Deletes the customer and all associated accounts from the database. Returns 204 if the customer was successfully deleted or 404 and an appropriate message if that customer could not be found.

Bank

GET /banks

Returns a list of all banks.

[
    {
        "id": 1,
        "name": "Royal Raccoon Bank"
    },
    {
        "id": 2,
        "name": "Bob's Bank",
    }
]

GET /banks/:id

Returns a bank with the matching id. If there is no bank, returns a message that the bank could not be found along with a 404.

{
    "id": 2,
    "name": "Bob's Bank",
}

Account

POST /account

Creates a new account. The account must belong to a customer and a bank. Return the new account details like so:

{
    "id": 3,
    "balance": 10000,
    "account_type": "checking",
    "customer_name": "Charlie Kozey",
    "bank_name": "Royal Raccoon Bank"
}

HINT: You might need to create more than one method with the functionality of to_dict in order to make this work.

About


Languages

Language:Python 100.0%