-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
63 lines (53 loc) · 1.95 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from fastapi import FastAPI, Request, status, Depends, HTTPException
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
from routers import posts, admin
# to run the app vvv
# uvicorn main:app --reload
# Instansiate FastAPI Class
# when running the model, "main" is the python file and "app"
# is the variable name that is holding the FastAPI class (main:app)
# Tags for the descriptions displayed on the autogenerated FastAPI docs
tags_metadata = [
{
"name": "transaction",
"description": "Automatically categorizes PLAID transactions into BudgetBlocks categories using the user's preferences or if they do not exist, the default preferences",
},
{
"name": "census",
"description": "Returns the categorized census average expenditures of the closest city in the census data or the region if the closest city is farther than 50 miles away",
},
{
"name": "update_users",
"description": "Updates a user's categorical preferences in the users table",
},
{
"name": "Admin",
"description": "Admin interface routes; accessible upon login through api.budgetblocks.org/admin"
},
{
"name": "reset_user",
"description": "Remove a user's custom preferences and replace them with the current defaults"
},
{
"name": "delete_user",
"description": "Delete a user from the user table"
}
]
app = FastAPI(openapi_tags=tags_metadata)
# Work around to allow the web team to connect to the DS API from a local host
# Currently allows connection from any origin
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
# allow_origin_regex="http://localhost:3000.*"
)
app.include_router(posts.router)
app.include_router(admin.router)
@app.get("/")
def root():
# Written as a dict but returns a json object
return {"message": 'Hello World!'}