🚨 fix some linter warnings
Some checks failed
Python formatting PEP8 / Python-PEP8 (push) Failing after 13s
Some checks failed
Python formatting PEP8 / Python-PEP8 (push) Failing after 13s
This commit is contained in:
parent
44b73ab89d
commit
a689b1c56d
4 changed files with 28 additions and 38 deletions
|
@ -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)
|
||||
|
@ -29,7 +31,6 @@ if config.config_file_name is not None:
|
|||
# target_metadata = mymodel.Base.metadata
|
||||
# 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,
|
||||
|
|
|
@ -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)
|
||||
|
|
29
app/main.py
29
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)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from sqlalchemy import Boolean, Column, Integer, String
|
||||
from sqlalchemy import Column, Integer, String
|
||||
|
||||
from database import Base
|
||||
|
||||
|
|
Loading…
Reference in a new issue