-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (33 loc) · 1022 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from fastapi import FastAPI
import helper
from fastapi.responses import JSONResponse
import pandas as pd
from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session
from typing import List, Dict
import crud, models, schemas
from database import SessionLocal, engine
import os
from dotenv import load_dotenv
load_dotenv()
models.Base.metadata.create_all(bind=engine)
HERTS_COVID_URL = os.getenv('HERTS_COVID_URL')
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
# Dependency
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
@app.get("/results/daily", response_model=schemas.Cases)
async def read_covid_test_results(db: Session = Depends(get_db)):
results = crud.get_covid_test_results(db)
return results
@app.get("/results/", response_model=List[schemas.Cases])
async def read_covid_test_results(db: Session = Depends(get_db)):
results = crud.get_covid_test_results(db)
return results