From d23f9af675d5bb90d57e2828545f963c1d49a0a2 Mon Sep 17 00:00:00 2001 From: LaPlazesDemon <164425143+LaPlazesDemon@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:43:04 -0400 Subject: [PATCH] Initial Commit --- api/main.py | 13 +++++++++++++ api/schema/book.py | 4 +++- pyproject.toml | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/main.py b/api/main.py index 1e5369c..b06f260 100644 --- a/api/main.py +++ b/api/main.py @@ -79,3 +79,16 @@ async def brew(): status_code=status.HTTP_418_IM_A_TEAPOT, detail="Cannot brew coffee with a teapot!" ) + +@app.get("/search/author/") +async def search_by_author(author: str): + return (book for book in books if author in book.author) + +@app.get("/search/pub_year/") +async def search_by_pub_year(year: int): + return (book for book in books if book.publication_year == year) + +@app.get('/info/average_rating') +async def get_average_rating(): + ratings = [book.rating for book in books] + return sum(ratings) / len(ratings) diff --git a/api/schema/book.py b/api/schema/book.py index 67327c5..58bd5b6 100644 --- a/api/schema/book.py +++ b/api/schema/book.py @@ -7,6 +7,7 @@ class BookBase(BaseModel): author: str publication_year: Optional[int] = None rating: Optional[int] = None + genre: str # TODO # Add a 'genre' field here. You'll need to add it in a few other places as well! @@ -24,7 +25,8 @@ def from_base(base: BookBase, id: int): title = base.title, author = base.author, publication_year = base.publication_year, - rating = base.rating + rating = base.rating, + genre = base.genre ) diff --git a/pyproject.toml b/pyproject.toml index f281748..38659e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ version = "0.1.0" description = "Example repo for 04APR New To Tech session" authors = ["Matt "] readme = "README.md" +package-mode = false [tool.poetry.dependencies] python = "^3.12"