Spaces:
Running
on
Zero
Running
on
Zero
from fastapi import FastAPI, Depends | |
from fastapi.responses import JSONResponse | |
from fastapi.requests import Request | |
from fastapi.exceptions import RequestValidationError | |
from fastapi.responses import JSONResponse | |
from fastapi.encoders import jsonable_encoder | |
from pydantic import BaseModel | |
from sqlalchemy.orm import Session | |
from . import models, schema, crud | |
from .database import SessionLocal, engine | |
models.Base.metadata.create_all(bind=engine) | |
app = FastAPI() | |
def get_db(): | |
db = SessionLocal() | |
try: | |
yield db | |
finally: | |
db.close() | |
def create_user(user: schema.UserCreate, db: Session = Depends(get_db)): | |
return crud.create_user(db=db, user=user) | |
def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): | |
return crud.get_users(db, skip=skip, limit=limit) | |
def read_user(user_id: int, db: Session = Depends(get_db)): | |
return crud.get_user(db, user_id=user_id) | |
def create_team(team: schema.TeamCreate, db: Session = Depends(get_db)): | |
return crud.create_team(db=db, team=team) | |
def read_teams(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): | |
return crud.get_teams(db, skip=skip, limit=limit) | |
def read_team(team_id: int, db: Session = Depends(get_db)): | |
return crud.get_team(db, team_id=team_id) |