Automated Action c5e673d2ea Implement complete beat marketplace API with FastAPI
- Set up FastAPI project structure with main.py and requirements.txt
- Created SQLite database models for users, beats, and transactions
- Implemented Alembic database migrations
- Added user authentication system with JWT tokens
- Created beat management endpoints (CRUD operations)
- Implemented purchase/transaction system
- Added file upload/download functionality for beat files
- Created health endpoint and API documentation
- Updated README with comprehensive documentation
- Fixed all linting issues with Ruff

Environment variables needed:
- SECRET_KEY: JWT secret key for authentication
2025-07-06 17:42:23 +00:00

36 lines
1.3 KiB
Python

from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from sqlalchemy.orm import Session
from app.db.session import get_db
from app.models.user import User
from app.core.security import verify_token
security = HTTPBearer()
async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security), db: Session = Depends(get_db)):
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
token = credentials.credentials
email = verify_token(token)
if email is None:
raise credentials_exception
user = db.query(User).filter(User.email == email).first()
if user is None:
raise credentials_exception
return user
async def get_current_active_user(current_user: User = Depends(get_current_user)):
if not current_user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
return current_user
async def get_current_producer(current_user: User = Depends(get_current_active_user)):
if not current_user.is_producer:
raise HTTPException(status_code=403, detail="Not a producer")
return current_user