-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoa_api.py
65 lines (52 loc) · 1.43 KB
/
oa_api.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
64
65
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
from analyse import analyse
from fastapi.middleware.cors import CORSMiddleware
from google.appengine.api import mail
from google.appengine.api import apiproxy_stub_map
app = FastAPI()
origins = [
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
# allow_credentials=True,
allow_methods=["POST", "OPTIONS"],
allow_headers=["*"],
)
class Form(BaseModel):
orgnr: str
year: int
period: int
debit_amount: float
credit_amount: float
turnover: float
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/orgnr/{orgnr}")
def read_item(
orgnr: int = 8888888,
from_and_included_date: Union[str, None] = None,
to_date: Union[str, None] = None,
from_and_included_account_id: Union[int, None] = None,
to_account_id: Union[int, None] = None
):
return analyse(
str(from_and_included_date),
str(to_date),
from_and_included_account_id,
to_account_id,
)
@app.post("/orid/{orid}")
def create_form(orid: str, data: Form):
mail.SendMailToAdmins(
sender="OA API <dontknow@example.com>",
subject="New form received",
body=f"New form received from {orid} with data {data}",
# make_sync_call=apiproxy_stub_map.MakeSyncCall
)
return {"orid": orid, "data": data}