Automated Action 771ee5214f Implement LinkedIn-based church management system with FastAPI
- Complete FastAPI application with authentication and JWT tokens
- SQLite database with SQLAlchemy ORM and Alembic migrations
- User management with profile features and search functionality
- LinkedIn-style networking with connection requests and acceptance
- Social features: posts, likes, comments, announcements, prayer requests
- Event management with registration system and capacity limits
- RESTful API endpoints for all features with proper authorization
- Comprehensive documentation and setup instructions

Key Features:
- JWT-based authentication with bcrypt password hashing
- User profiles with bio, position, contact information
- Connection system for church member networking
- Community feed with post interactions
- Event creation, registration, and attendance tracking
- Admin role-based permissions
- Health check endpoint and API documentation

Environment Variables Required:
- SECRET_KEY: JWT secret key for token generation
2025-07-01 12:28:10 +00:00

69 lines
1.8 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from typing import List
from app.db.base import get_db
from app.models.user import User
from app.schemas.user import UserResponse, UserUpdate
from app.api.auth import get_current_user
router = APIRouter()
@router.get("/", response_model=List[UserResponse])
def get_users(
skip: int = 0,
limit: int = 100,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
users = db.query(User).filter(User.is_active).offset(skip).limit(limit).all()
return users
@router.get("/{user_id}", response_model=UserResponse)
def get_user(
user_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
user = db.query(User).filter(User.id == user_id, User.is_active).first()
if user is None:
raise HTTPException(status_code=404, detail="User not found")
return user
@router.put("/me", response_model=UserResponse)
def update_my_profile(
user_update: UserUpdate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
for field, value in user_update.dict(exclude_unset=True).items():
setattr(current_user, field, value)
db.commit()
db.refresh(current_user)
return current_user
@router.get("/search/{query}", response_model=List[UserResponse])
def search_users(
query: str,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
users = (
db.query(User)
.filter(
User.is_active,
(
User.first_name.contains(query)
| User.last_name.contains(query)
| User.email.contains(query)
| User.position.contains(query)
),
)
.limit(20)
.all()
)
return users