
Features: - User registration and authentication with JWT tokens - Multi-level admin access (Admin and Super Admin) - Gym management with membership plans - Subscription management with payment integration - Stripe and Paystack payment gateway support - Role-based access control - SQLite database with Alembic migrations - Comprehensive API endpoints with FastAPI - Database models for users, gyms, memberships, subscriptions, and transactions - Admin endpoints for user management and financial reporting - Health check and documentation endpoints Core Components: - FastAPI application with CORS support - SQLAlchemy ORM with relationship mapping - JWT-based authentication with bcrypt password hashing - Payment service abstraction for multiple gateways - Pydantic schemas for request/response validation - Alembic database migration system - Admin dashboard functionality - Environment variable configuration
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.session import get_db
|
|
from app.core.deps import get_current_active_user
|
|
from app.models.user import User
|
|
from app.models.membership import GymMembership
|
|
from app.models.subscription import Subscription
|
|
from app.schemas.user import User as UserSchema, UserUpdate
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/me", response_model=UserSchema)
|
|
def read_user_me(current_user: User = Depends(get_current_active_user)):
|
|
return current_user
|
|
|
|
|
|
@router.put("/me", response_model=UserSchema)
|
|
def update_user_me(
|
|
user_update: UserUpdate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_active_user),
|
|
):
|
|
user = db.query(User).filter(User.id == current_user.id).first()
|
|
if not user:
|
|
raise HTTPException(status_code=404, detail="User not found")
|
|
|
|
update_data = user_update.dict(exclude_unset=True)
|
|
for field, value in update_data.items():
|
|
setattr(user, field, value)
|
|
|
|
db.commit()
|
|
db.refresh(user)
|
|
return user
|
|
|
|
|
|
@router.get("/me/memberships")
|
|
def get_user_memberships(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_active_user)
|
|
):
|
|
memberships = (
|
|
db.query(GymMembership).filter(GymMembership.user_id == current_user.id).all()
|
|
)
|
|
return memberships
|
|
|
|
|
|
@router.get("/me/subscriptions")
|
|
def get_user_subscriptions(
|
|
db: Session = Depends(get_db), current_user: User = Depends(get_current_active_user)
|
|
):
|
|
subscriptions = (
|
|
db.query(Subscription).filter(Subscription.user_id == current_user.id).all()
|
|
)
|
|
return subscriptions
|