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 app import crud, schemas
|
||||
from app.database import SessionLocal, engine
|
||||
from app import models
|
||||
from fastapi import FastAPI, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from app import crud, models, schemas
|
||||
from app.database import engine, get_db
|
||||
|
||||
# Create tables if not exist
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
|
@ -12,23 +12,14 @@ app = FastAPI(title="Data Lab API")
|
|||
def root():
|
||||
return {"message": "Welcome to Data Lab API"}
|
||||
|
||||
@app.get("/customers")
|
||||
def get_customers():
|
||||
db = SessionLocal()
|
||||
customers = crud.get_customers(db)
|
||||
db.close()
|
||||
return customers
|
||||
@app.get("/customers", response_model=list[schemas.Customer])
|
||||
def get_customers(db: Session = Depends(get_db)):
|
||||
return crud.get_customers(db)
|
||||
|
||||
@app.get("/accounts")
|
||||
def get_accounts():
|
||||
db = SessionLocal()
|
||||
accounts = crud.get_accounts(db)
|
||||
db.close()
|
||||
return accounts
|
||||
@app.get("/accounts", response_model=list[schemas.Account])
|
||||
def get_accounts(db: Session = Depends(get_db)):
|
||||
return crud.get_accounts(db)
|
||||
|
||||
@app.get("/transactions")
|
||||
def get_accounts():
|
||||
db = SessionLocal()
|
||||
transactions = crud.get_transactions(db)
|
||||
db.close()
|
||||
return transactions
|
||||
@app.get("/transactions", response_model=list[schemas.Transaction])
|
||||
def get_transactions(db: Session = Depends(get_db)):
|
||||
return crud.get_transactions(db)
|
||||
|
|
|
|||
Loading…
Reference in a new issue