From a689b1c56ddbe57c008eb136aa79db16d911e152 Mon Sep 17 00:00:00 2001 From: Finn Christiansen Date: Fri, 11 Aug 2023 22:47:08 +0200 Subject: [PATCH] :rotating_light: fix some linter warnings --- alembic/env.py | 5 +++-- app/crud/item.py | 30 ------------------------------ app/main.py | 29 ++++++++++++++++++++++++----- app/models/item.py | 2 +- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/alembic/env.py b/alembic/env.py index 60b0977..c6596af 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -7,6 +7,8 @@ from alembic import context import os import sys from dotenv import load_dotenv +from app.models import models + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) load_dotenv(os.path.join(BASE_DIR, ".env")) sys.path.append(BASE_DIR) @@ -27,9 +29,8 @@ if config.config_file_name is not None: # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata -#target_metadata = None +# target_metadata = None -from app.models import models target_metadata = models.Base.metadata # other values from the config, defined by the needs of env.py, diff --git a/app/crud/item.py b/app/crud/item.py index a395336..120bf21 100644 --- a/app/crud/item.py +++ b/app/crud/item.py @@ -1,6 +1,3 @@ -from fastapi import HTTPException -from sqlalchemy.orm import Session - from models import Item from schemas.schemas import ItemCreate, ItemUpdate from crud.base import CRUDBase @@ -8,33 +5,6 @@ from crud.base import CRUDBase class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]): pass - # def get_item(self, db: Session, item_id: int): - # item = db.query(Item).filter(Item.id == item_id).first() - # if not item: - # raise HTTPException(status_code=404, detail="Item not found") - # return item - - # def get_items(self, db: Session, skip: int = 0, limit: int = 100): - # return db.query(Item).offset(skip).limit(limit).all() - - # def create_item(self, db: Session, item: ItemCreate): - # db_item = Item(title=item.title, description=item.description) - # db.add(db_item) - # db.commit() - # db.refresh(db_item) - # return db_item - - # def update_item(self, db: Session, item: ItemUpdate): - # db_item = Item(title=item.title, description=item.description) - # db.add(db_item) - # db.commit() - # db.refresh(db_item) - # return db_item - - # def delete_item(self, db: Session, item_id: int): - # db.query(Item).filter(Item.id == item_id).first().delete() - # db.commit() - # return item = CRUDItem(Item) diff --git a/app/main.py b/app/main.py index 5097c9c..0fe6165 100644 --- a/app/main.py +++ b/app/main.py @@ -27,25 +27,44 @@ async def root(): @app.get("/items/{item_id}", response_model=schemas.Item) -async def get_item(*, db: Session = Depends(get_db), item_id: int): +async def get_item( + *, + db: Session = Depends(get_db), + item_id: int +): return crud.item.get(db, item_id) @app.get("/items/", response_model=list[schemas.Item]) -async def get_items(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): +async def get_items( + skip: int = 0, + limit: int = 100, + db: Session = Depends(get_db) +): return crud.item.get_multi(db, skip=skip, limit=limit) @app.post("/items/", response_model=schemas.Item) -async def create_item(item: schemas.ItemCreate, db: Session = Depends(get_db)): +async def create_item( + item: schemas.ItemCreate, + db: Session = Depends(get_db) +): return crud.item.create(db=db, item=item) @app.put("/items/{item_id}", response_model=schemas.ItemUpdate) -async def update_item(item: schemas.ItemUpdate, db: Session = Depends(get_db)): +async def update_item( + item: schemas.ItemUpdate, + db: Session = Depends(get_db) +): return crud.item.update(db=db, item=item) @app.delete("/items/{item_id}") -async def delete_item(*, item: schemas.ItemUpdate, db: Session = Depends(get_db), item_id: int): +async def delete_item( + *, + item: schemas.ItemUpdate, + db: Session = Depends(get_db), + item_id: int +): return crud.remove(item_id) diff --git a/app/models/item.py b/app/models/item.py index f881d4e..0310618 100644 --- a/app/models/item.py +++ b/app/models/item.py @@ -1,4 +1,4 @@ -from sqlalchemy import Boolean, Column, Integer, String +from sqlalchemy import Column, Integer, String from database import Base