feat: crud and backups are working
This commit is contained in:
+44
-4
@@ -1,8 +1,48 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from . import schemas, crud
|
||||
from .database import SessionLocal, engine, Base
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def read_root():
|
||||
return {"hello": "world"}
|
||||
# Dependency
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@app.get("/check-health")
|
||||
def health_check():
|
||||
return {"Health": "Super Healthy!"}
|
||||
|
||||
|
||||
@app.post("/items/", response_model=schemas.Item)
|
||||
def create_item(item: schemas.ItemCreate, db: Session = Depends(get_db)):
|
||||
return crud.create_item(db, item)
|
||||
|
||||
|
||||
@app.get("/items/", response_model=list[schemas.Item])
|
||||
def read_items(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
|
||||
return crud.get_items(db, skip, limit)
|
||||
|
||||
|
||||
@app.get("/items/{item_id}", response_model=schemas.Item)
|
||||
def read_item(item_id: int, db: Session = Depends(get_db)):
|
||||
db_item = crud.get_item(db, item_id)
|
||||
if db_item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return db_item
|
||||
|
||||
|
||||
@app.delete("/items/{item_id}", response_model=schemas.Item)
|
||||
def delete_item(item_id: int, db: Session = Depends(get_db)):
|
||||
item = crud.delete_item(db, item_id)
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return item
|
||||
|
||||
Reference in New Issue
Block a user