-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
19,098 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# FastAPI specific | ||
*.log | ||
*.pot | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
*.db | ||
*.sqlite3 | ||
*.sql | ||
*.env | ||
|
||
# Virtual environment | ||
venv/ | ||
env/ | ||
ENV/ | ||
|
||
# Node modules (for React) | ||
node_modules/ | ||
|
||
# React build files | ||
build/ | ||
dist/ | ||
*.map | ||
|
||
# Logs | ||
logs/ | ||
*.log | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# Coverage reports | ||
htmlcov/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
|
||
# Static and media files (for FastAPI) | ||
static/ | ||
media/ | ||
|
||
# MySQL dump files | ||
*.sql | ||
|
||
# Other unneeded files | ||
*.swp | ||
*.swo | ||
|
||
# NPM debug files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# IDE-specific files | ||
.idea/ | ||
.vscode/ | ||
|
||
# Testing outputs | ||
coverage/ | ||
*.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from fastapi import FastAPI, HTTPException | ||
from pydantic import BaseModel | ||
from typing import List | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
app = FastAPI() | ||
|
||
# Adding CORS middleware to allow requests from React frontend | ||
origins = [ | ||
"http://localhost:3000", # Frontend URL | ||
] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
# Accident Hotspot model | ||
class AccidentHotspot(BaseModel): | ||
lat: float | ||
lng: float | ||
intensity: int | ||
description: str | ||
|
||
# Mock data simulating accident hotspots | ||
mock_hotspots = [ | ||
# One hotspot near the user's location | ||
{"lat": 25.319000, "lng": 55.375000, "intensity": 6, "description": "High accident risk, close to your location."}, | ||
|
||
# Two hotspots far from the user's location | ||
{"lat": 25.3573, "lng": 55.4033, "intensity": 5, "description": "Moderate accident risk, located further away."}, | ||
{"lat": 25.3625, "lng": 55.4307, "intensity": 4, "description": "Occasional accidents in residential zone, located far away."}, | ||
] | ||
|
||
@app.get("/api/accident-hotspots", response_model=List[AccidentHotspot]) | ||
async def get_accident_hotspots(): | ||
return mock_hotspots | ||
|
||
# User authentication endpoints | ||
class User(BaseModel): | ||
username: str | ||
password: str | ||
first_name: str = None | ||
last_name: str = None | ||
|
||
fake_user_db = {} | ||
|
||
@app.post("/signup") | ||
async def signup(user: User): | ||
if user.username in fake_user_db: | ||
raise HTTPException(status_code=400, detail="Username already exists") | ||
fake_user_db[user.username] = { | ||
"password": user.password, | ||
"first_name": user.first_name, | ||
"last_name": user.last_name, | ||
} | ||
return {"message": "Signup successful"} | ||
|
||
@app.post("/login") | ||
async def login(user: User): | ||
if user.username not in fake_user_db or fake_user_db[user.username]["password"] != user.password: | ||
raise HTTPException(status_code=400, detail="Incorrect username or password") | ||
return { | ||
"message": "Login successful", | ||
"first_name": fake_user_db[user.username]["first_name"], | ||
"last_name": fake_user_db[user.username]["last_name"] | ||
} |
Oops, something went wrong.