Skip to content

Commit

Permalink
feat: project kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
h0m4m committed Oct 6, 2024
1 parent 02613b2 commit 7f2636c
Show file tree
Hide file tree
Showing 27 changed files with 19,098 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .gitignore
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
70 changes: 70 additions & 0 deletions backend/main.py
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"]
}
Loading

0 comments on commit 7f2636c

Please sign in to comment.