GithubHelp home page GithubHelp logo

phase-4-flask-practice-books's Introduction

Flask Practice - Books

This application is being built to track books, publishers, and authors.

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:

Book

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

  • page_count (integer): Cannot be null, must be greater than 0

Publisher

  • name (string): Cannot be null

  • founding_year (integer): Cannot be null, must be between 1600 and the current year

Author

  • name (string): Cannot be null

  • pen_name (string)

Relationships

This is a many-to-many relationship.

  • An author has many books and a book belongs to an author.

  • A publisher has many books and a book belongs to a publisher.

  • A publisher has many authors and an author has many publishers through books.

Author --< Book >-- Publisher

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:

Author Routes

GET /authors/:id

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

Format your author object like so:

    {
        "id": 1,
        "name": "Ursula K. Le Guin",
        "pen_name": null,
        "books": [
            {
                "id": 2,
                "title": "A Wizard of Earthsea",
                "page_count": 150,
                "author_name": "Ursula K. Le Guin",
                "publisher_name": "Random House"
            },
            {
                "id": 3,
                "title": "The Left Hand of Darkness",
                "page_count": 200,
                "author_name": "Ursula K. Le Guin",
                "publisher_name": "Random House"
            },
        ]
    }

DELETE /author/:id

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

Book Routes

GET /books

Returns a list of all books formatted like so:

[
    {
        "id": 1,
        "name": "The Catcher in the Rye",
        "page_count": 234,
        "author_name": "J.D. Salinger",
        "publisher_name": "Little, Brown and Company"
    },
    {
        "id": 2,
        "name": "A Wizard of Earthsea",
        "page_count": 205,
        "author_name": "Ursula K. Le Guin",
        "publisher_name": "Parnassus Press"
    }
]

POST /books

Creates a new book. The book must belong to an author and a publisher. Return the new book details like so:

    {
        "id": 4,
        "name": "The Tombs of Atuan",
        "page_count": 163,
        "author_name": "Ursula K. Le Guin",
        "publisher_name": "Parnassus Press"
    }

Publisher Routes

GET /publishers/:id

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

{
    "id": 1,
    "name": "Parnassus Press",
    "founding_year": 1849,
    "authors": [
        {
            "id": 1,
            "name": "Ursula K. Le Guin",
            "pen_name": null
        },
        {
            "id": 2,
            "name": "Stephen King",
            "pen_name": "Richard Bachman",
        }
    ]
}

Hint: You may need to pay attention to how you return your data as the author needs to be returned without their books for this route.

phase-4-flask-practice-books's People

Contributors

brewchetta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.