Automated Action 9ca9d35a1a Implement complete Urban Real Estate API backend
- Set up FastAPI project structure with modular architecture
- Create comprehensive database models for users, properties, messages, notifications, and payments
- Implement JWT-based authentication with role-based access control (Seeker, Agent, Landlord, Admin)
- Build property listings CRUD with advanced search and filtering capabilities
- Add dedicated affordable housing endpoints for Nigerian market focus
- Create real-time messaging system between users
- Implement admin dashboard with property approval workflow and analytics
- Add notification system for user alerts
- Integrate Paystack payment gateway for transactions
- Set up SQLite database with Alembic migrations
- Include comprehensive health check and API documentation
- Add proper error handling and validation throughout
- Follow FastAPI best practices with Pydantic schemas and dependency injection
2025-06-27 12:24:06 +00:00

44 lines
1.2 KiB
Python

from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from sqlalchemy.orm import Session
from app.core.security import verify_token
from app.db.session import SessionLocal
from app.models.user import User
security = HTTPBearer()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
def get_current_user(
credentials: HTTPAuthorizationCredentials = Depends(security),
db: Session = Depends(get_db)
) -> User:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
token = credentials.credentials
username = verify_token(token)
if username is None:
raise credentials_exception
user = db.query(User).filter(User.username == username).first()
if user is None:
raise credentials_exception
return user
def get_current_active_user(current_user: User = Depends(get_current_user)) -> User:
if not current_user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
return current_user