
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
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from sqlalchemy import (
|
|
Column,
|
|
Integer,
|
|
String,
|
|
DateTime,
|
|
Float,
|
|
ForeignKey,
|
|
Boolean,
|
|
Enum,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
import enum
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class PlanType(str, enum.Enum):
|
|
BASIC = "basic"
|
|
PREMIUM = "premium"
|
|
VIP = "vip"
|
|
|
|
|
|
class MembershipStatus(str, enum.Enum):
|
|
ACTIVE = "active"
|
|
INACTIVE = "inactive"
|
|
EXPIRED = "expired"
|
|
SUSPENDED = "suspended"
|
|
|
|
|
|
class MembershipPlan(Base):
|
|
__tablename__ = "membership_plans"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
gym_id = Column(Integer, ForeignKey("gyms.id"), nullable=False)
|
|
name = Column(String, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
plan_type = Column(Enum(PlanType), nullable=False)
|
|
price = Column(Float, nullable=False)
|
|
duration_days = Column(Integer, nullable=False)
|
|
features = Column(Text, nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
gym = relationship("Gym", back_populates="membership_plans")
|
|
subscriptions = relationship("Subscription", back_populates="membership_plan")
|
|
|
|
|
|
class GymMembership(Base):
|
|
__tablename__ = "gym_memberships"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
gym_id = Column(Integer, ForeignKey("gyms.id"), nullable=False)
|
|
status = Column(Enum(MembershipStatus), default=MembershipStatus.ACTIVE)
|
|
joined_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
user = relationship("User", back_populates="gym_memberships")
|
|
gym = relationship("Gym", back_populates="gym_memberships")
|