Track A (Infrastructure & Data Layer): - docker-compose.yml with all 7 services (nginx, frontend, api, mcp, renderer, worker, postgres, redis) - docker-compose.override.yml for local dev (hot reload, port exposure) - PostgreSQL init.sql with full schema (15 tables, pgvector indexes, creator economy stubs) - .env.example with all required environment variables Track A+B (API Layer): - FastAPI app with 10 routers (auth, shaders, feed, votes, generate, desires, users, payments, mcp_keys, health) - SQLAlchemy ORM models for all 15 tables - Pydantic schemas for all request/response types - JWT auth middleware (access + refresh tokens, Redis blocklist) - Redis rate limiting middleware - Celery worker config with job stubs (render, embed, generate, feed cache, expire bounties) - Alembic migration framework Service stubs: - MCP server (health endpoint, 501 for all tools) - Renderer service (Express + Puppeteer scaffold, 501 for /render) - Frontend (package.json with React/Vite/Three.js/TanStack/Tailwind deps) - Nginx reverse proxy config (/, /api, /mcp, /renders) Project: - DECISIONS.md with 11 recorded architectural decisions - README.md with architecture overview - Sample shader seed data (plasma, fractal noise, raymarched sphere)
68 lines
2 KiB
Python
68 lines
2 KiB
Python
"""Votes & engagement router."""
|
|
|
|
from uuid import UUID
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
|
|
from app.database import get_db
|
|
from app.models import User, Shader, Vote, EngagementEvent
|
|
from app.schemas import VoteCreate
|
|
from app.middleware.auth import get_current_user, get_optional_user
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/shaders/{shader_id}/vote", status_code=status.HTTP_200_OK)
|
|
async def vote_shader(
|
|
shader_id: UUID,
|
|
body: VoteCreate,
|
|
db: AsyncSession = Depends(get_db),
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
# Verify shader exists
|
|
shader = (await db.execute(select(Shader).where(Shader.id == shader_id))).scalar_one_or_none()
|
|
if not shader:
|
|
raise HTTPException(status_code=404, detail="Shader not found")
|
|
|
|
# Upsert vote
|
|
existing = (await db.execute(
|
|
select(Vote).where(Vote.user_id == user.id, Vote.shader_id == shader_id)
|
|
)).scalar_one_or_none()
|
|
|
|
if existing:
|
|
existing.value = body.value
|
|
else:
|
|
db.add(Vote(user_id=user.id, shader_id=shader_id, value=body.value))
|
|
|
|
# TODO: Recalculate hot score (Track F)
|
|
return {"status": "ok", "value": body.value}
|
|
|
|
|
|
@router.delete("/shaders/{shader_id}/vote", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def remove_vote(
|
|
shader_id: UUID,
|
|
db: AsyncSession = Depends(get_db),
|
|
user: User = Depends(get_current_user),
|
|
):
|
|
existing = (await db.execute(
|
|
select(Vote).where(Vote.user_id == user.id, Vote.shader_id == shader_id)
|
|
)).scalar_one_or_none()
|
|
|
|
if existing:
|
|
await db.delete(existing)
|
|
# TODO: Recalculate hot score (Track F)
|
|
|
|
|
|
@router.post("/shaders/{shader_id}/replay", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def report_replay(
|
|
shader_id: UUID,
|
|
db: AsyncSession = Depends(get_db),
|
|
user: User | None = Depends(get_optional_user),
|
|
):
|
|
event = EngagementEvent(
|
|
user_id=user.id if user else None,
|
|
shader_id=shader_id,
|
|
event_type="replay",
|
|
)
|
|
db.add(event)
|