You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
961 B
34 lines
961 B
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
|
|
|