
- Setup project structure and basic FastAPI application - Define database models for users, profiles, matches, and messages - Set up database connection and create Alembic migrations - Implement user authentication and registration endpoints - Create API endpoints for profile management, matches, and messaging - Add filtering and search functionality for tech profiles - Setup environment variable configuration - Create README with project information and setup instructions
67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
from typing import Any, List
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_active_user, get_current_active_superuser
|
|
from app.db.session import get_db
|
|
from app.schemas.user import User, UserUpdate
|
|
from app.crud import user
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/me", response_model=User)
|
|
def read_user_me(
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
"""
|
|
Get current user
|
|
"""
|
|
return current_user
|
|
|
|
|
|
@router.put("/me", response_model=User)
|
|
def update_user_me(
|
|
*,
|
|
db: Session = Depends(get_db),
|
|
user_in: UserUpdate,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
"""
|
|
Update current user
|
|
"""
|
|
updated_user = user.update(db, db_obj=current_user, obj_in=user_in)
|
|
return updated_user
|
|
|
|
|
|
@router.get("/{user_id}", response_model=User)
|
|
def read_user_by_id(
|
|
user_id: int,
|
|
current_user: User = Depends(get_current_active_user),
|
|
db: Session = Depends(get_db),
|
|
) -> Any:
|
|
"""
|
|
Get user by ID
|
|
"""
|
|
user_obj = user.get(db, id=user_id)
|
|
if not user_obj:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="User not found",
|
|
)
|
|
return user_obj
|
|
|
|
|
|
@router.get("/", response_model=List[User])
|
|
def read_users(
|
|
db: Session = Depends(get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(get_current_active_superuser),
|
|
) -> Any:
|
|
"""
|
|
Retrieve users (superuser only)
|
|
"""
|
|
users = user.get_multi(db, skip=skip, limit=limit)
|
|
return users |