Files
proc-rota/web/main.py
T
2022-07-11 19:46:40 +01:00

63 lines
1.3 KiB
Python

import uvicorn
from fastapi import FastAPI, Query
from pydantic import BaseModel
from fastapi_sqlalchemy import DBSessionMiddleware, db
import os
from dotenv import load_dotenv
from rota.shifts import SingleShift, ShiftConstraint
from web.models import SingleShift as ModelSingleShift
from web.models import ShiftConstraint as ModelShiftConstraint
#from rota.wokers
load_dotenv('../.env')
app = FastAPI()
app.add_middleware(DBSessionMiddleware, db_url="sqlite:///test.db")
@app.post('/shifts/', response_model=SingleShift)
async def shifts(shift: ModelSingleShift):
db_shift = ModelSingleShift(name=shift.name, length=shift.length)
db.session.add(db_shift)
db.session.commit()
return db_shift
@app.get("/shifts/")
async def shifts():
shifts = db.session.query(ModelSingleShift).all()
return shifts
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/files/{file_path:path}")
async def read_file(file_path: str):
return {"file_path": file_path}
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
@app.post("/items/")
async def create_item(item: Item):
item.name + item.price
return item
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=8008)