Skip to content

Commit bb167dd

Browse files
authored
adds json upload (#8)
1 parent 136bda3 commit bb167dd

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

app.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def get_lookup_list(request: Request, project_id: str, lookup_list_id: str):
5252
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=resp.json())
5353

5454

55-
@app.post("/project/{project_id}/import")
56-
async def post_import(request: Request, project_id: str):
55+
@app.post("/project/{project_id}/import_file")
56+
async def post_import_file(request: Request, project_id: str):
5757
try:
5858
user_id = get_user_id_from_request(request)
5959
except KeyError:
@@ -62,7 +62,7 @@ async def post_import(request: Request, project_id: str):
6262
content={"error_code": ErrorCodes.UNRECOGNIZED_USER},
6363
)
6464
request_body = await request.json()
65-
url = f"{BASE_URI}/project/{project_id}/import"
65+
url = f"{BASE_URI}/project/{project_id}/import_file"
6666
resp = requests.post(
6767
url,
6868
json={
@@ -75,6 +75,27 @@ async def post_import(request: Request, project_id: str):
7575
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=resp.json())
7676

7777

78+
@app.post("/project/{project_id}/import_json")
79+
async def post_import_json(request: Request, project_id: str):
80+
try:
81+
user_id = get_user_id_from_request(request)
82+
except KeyError:
83+
return responses.JSONResponse(
84+
status_code=status.HTTP_401_UNAUTHORIZED,
85+
content={"error_code": ErrorCodes.UNRECOGNIZED_USER},
86+
)
87+
request_body = await request.json()
88+
url = f"{BASE_URI}/project/{project_id}/import_json"
89+
resp = requests.post(
90+
url,
91+
json={
92+
"user_id": user_id,
93+
"records": request_body["records"],
94+
},
95+
)
96+
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=resp.json())
97+
98+
7899
@app.post("/project/{project_id}/associations")
79100
async def post_associations(request: Request, project_id: str):
80101
try:

0 commit comments

Comments
 (0)