-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
29 lines (22 loc) · 1011 Bytes
/
Copy pathweb.py
File metadata and controls
29 lines (22 loc) · 1011 Bytes
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
import re
from typing import Dict, Union
from fastapi import FastAPI, Query, HTTPException, status
from .schemas import Entry, ProcessInfo
from .app import main as collector
app = FastAPI()
@app.get("/", status_code=status.HTTP_200_OK, response_model=ProcessInfo)
async def main(process_number: str = Query(..., alias="q")) -> ProcessInfo:
entry = Entry(process_number=process_number)
result = await collector(entry)
pattern = re.compile(r"^\d{7}-\d{2}\.\d{4}\.\d\.\d{2}\.\d{4}$")
if not pattern.match(process_number):
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Process number must have this parttern: XXXXXXX-XX.XXXX.X.XX.XXXX",
)
elif hasattr(result, "first_instance") and (not result.first_instance and not result.second_instance):
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Process number {process_number} not found",
)
return result