Update app/main.py
This commit is contained in:
parent
e7382cb7b8
commit
9962b54521
1 changed files with 13 additions and 22 deletions
35
app/main.py
35
app/main.py
|
|
@ -1,7 +1,7 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, Depends
|
||||||
from app import crud, schemas
|
from sqlalchemy.orm import Session
|
||||||
from app.database import SessionLocal, engine
|
from app import crud, models, schemas
|
||||||
from app import models
|
from app.database import engine, get_db
|
||||||
|
|
||||||
# Create tables if not exist
|
# Create tables if not exist
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
@ -12,23 +12,14 @@ app = FastAPI(title="Data Lab API")
|
||||||
def root():
|
def root():
|
||||||
return {"message": "Welcome to Data Lab API"}
|
return {"message": "Welcome to Data Lab API"}
|
||||||
|
|
||||||
@app.get("/customers")
|
@app.get("/customers", response_model=list[schemas.Customer])
|
||||||
def get_customers():
|
def get_customers(db: Session = Depends(get_db)):
|
||||||
db = SessionLocal()
|
return crud.get_customers(db)
|
||||||
customers = crud.get_customers(db)
|
|
||||||
db.close()
|
|
||||||
return customers
|
|
||||||
|
|
||||||
@app.get("/accounts")
|
@app.get("/accounts", response_model=list[schemas.Account])
|
||||||
def get_accounts():
|
def get_accounts(db: Session = Depends(get_db)):
|
||||||
db = SessionLocal()
|
return crud.get_accounts(db)
|
||||||
accounts = crud.get_accounts(db)
|
|
||||||
db.close()
|
|
||||||
return accounts
|
|
||||||
|
|
||||||
@app.get("/transactions")
|
@app.get("/transactions", response_model=list[schemas.Transaction])
|
||||||
def get_accounts():
|
def get_transactions(db: Session = Depends(get_db)):
|
||||||
db = SessionLocal()
|
return crud.get_transactions(db)
|
||||||
transactions = crud.get_transactions(db)
|
|
||||||
db.close()
|
|
||||||
return transactions
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue