|
|
|
from fastapi import FastAPI, Depends
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
import crud
|
|
|
|
import schemas
|
|
|
|
from database import SessionLocal
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
def get_db():
|
|
|
|
db = SessionLocal()
|
|
|
|
try:
|
|
|
|
yield db
|
|
|
|
finally:
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/equipment", response_model=schemas.Equipment)
|
|
|
|
def create_equipment(equipment: schemas.EquipmentCreate, db: Session = Depends(get_db)):
|
|
|
|
db_equipment = crud.create_equipment(db=db, equipment=equipment)
|
|
|
|
return db_equipment
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/equipments", response_model=list[schemas.Equipment])
|
|
|
|
def get_equipments(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
|
|
|
|
equipments = crud.get_equipments(db, skip=skip, limit=limit)
|
|
|
|
return equipments
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/equipments/{equipment_id}", response_model=schemas.Equipment)
|
|
|
|
def get_equipment(equipment_id: int, db: Session = Depends(get_db)):
|
|
|
|
equipment = crud.get_equipment(db=db, equipment_id=equipment_id)
|
|
|
|
return equipment
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/devices", response_model=list[schemas.Device])
|
|
|
|
def get_devices(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
|
|
|
|
devices = crud.get_devices(db, skip=skip, limit=limit)
|
|
|
|
return devices
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/devices/{device_id}", response_model=schemas.Device)
|
|
|
|
def get_device(device_id: int, db: Session = Depends(get_db)):
|
|
|
|
device = crud.get_device(db=db, device_id=device_id)
|
|
|
|
return device
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/devices", response_model=schemas.Device)
|
|
|
|
def create_device(device: schemas.DeviceCreate, db: Session = Depends(get_db)):
|
|
|
|
db_device = crud.create_device(db=db, device=device)
|
|
|
|
return db_device
|