-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (52 loc) · 1.82 KB
/
app.py
File metadata and controls
66 lines (52 loc) · 1.82 KB
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
66
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from views import add_person, remove_person, get_people_in, get_logs, get_people_out
from utils import save_image
import os
app = FastAPI()
UPLOAD_DIR = "uploads"
os.makedirs(UPLOAD_DIR, exist_ok=True)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class AddPersonRequest(BaseModel):
aadhar: int
name: str
class RemovePersonRequest(BaseModel):
aadhar: int
@app.post("/removePerson")
def remove_person_endpoint(data: RemovePersonRequest):
success = remove_person(data.aadhar)
if not success:
raise HTTPException(status_code=404, detail="Person not found")
return {"message": "Person removed successfully"}
@app.get("/getPeopleIn")
def get_people_in_endpoint():
return get_people_in()
@app.get("/getLogs")
def get_logs_endpoint():
return get_logs()
@app.get("/getRecentExits")
def get_recent_exits():
return get_people_out()
@app.post("/registerUser")
async def register_user(
file: UploadFile = File(...),
isDigital: bool = Form(...)
):
print("Received file:", file.filename)
try:
file_path = save_image(file=file, upload_dir=UPLOAD_DIR)
# print("File saved at:", file_path) #Uncomment for debugging
# print("isdigital:", isDigital) #Uncomment for debugging
aadhar, name = add_person(path=file_path, isDigital=isDigital)
# print("User registered:", aadhar, name) #Uncomment for debugging
return aadhar
except Exception as e:
# print("Error:", e) #Uncomment for debugging
raise HTTPException(status_code=500, detail="Failed to register user")