Backend (FastAPI + Python 3.12): - Multi-tenant auth with JWT: login, register, refresh, Meta OAuth - Business & BusinessConfig management - WhatsApp webhook with HMAC signature verification - Bot engine powered by Claude AI - Calendar availability with Redis caching - Reservations CRUD with status management - Dashboard analytics (stats, agenda, peak hours) - Billing & plan management - Admin panel with platform-wide stats - Async bcrypt via asyncio.to_thread - IntegrityError handling for concurrent registration race conditions Frontend (React 18 + Vite + Tailwind CSS): - Multi-step guided registration form with helper text on every field - Login page with show/hide password toggle - Protected routes with AuthContext - Dashboard with stats cards, bar chart, and daily agenda - Reservations list with search, filters, and inline status actions - Calendar with weekly view, slot availability, and date blocking - Config page: business info, schedules, bot personality - Billing page with plan comparison and usage bar Design system: - Bricolage Grotesque + DM Sans typography - Emerald primary palette with semantic color tokens - scale(0.97) button press feedback, ease-out animations - Skeleton loaders, stagger animations, prefers-reduced-motion support - Accessible: aria-labels, visible focus rings, 4.5:1 contrast Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
from datetime import date
|
|
|
|
from fastapi import HTTPException, status
|
|
from sqlalchemy import and_, func, select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.modules.billing.schemas import PLAN_LIMITS, PlanRead, UsageRead
|
|
from app.modules.business.models import Business
|
|
from app.modules.business.service import get_business
|
|
from app.modules.reservations.models import Reservation
|
|
|
|
VALID_PLANS = set(PLAN_LIMITS.keys())
|
|
|
|
|
|
async def get_plan(db: AsyncSession, business_id: int) -> PlanRead:
|
|
business = await get_business(db, business_id)
|
|
limit = PLAN_LIMITS[business.plan]
|
|
return PlanRead(
|
|
plan=business.plan,
|
|
status=business.status,
|
|
monthly_limit=limit,
|
|
is_unlimited=limit == -1,
|
|
)
|
|
|
|
|
|
async def upgrade_plan(db: AsyncSession, business_id: int, new_plan: str) -> PlanRead:
|
|
if new_plan not in VALID_PLANS:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
detail=f"Plan inválido. Opciones: {', '.join(VALID_PLANS)}",
|
|
)
|
|
business = await get_business(db, business_id)
|
|
business.plan = new_plan
|
|
await db.commit()
|
|
await db.refresh(business)
|
|
return await get_plan(db, business_id)
|
|
|
|
|
|
async def get_usage(db: AsyncSession, business_id: int) -> UsageRead:
|
|
business = await get_business(db, business_id)
|
|
month_start = date.today().replace(day=1)
|
|
|
|
result = await db.execute(
|
|
select(func.count(Reservation.id)).where(
|
|
and_(
|
|
Reservation.business_id == business_id,
|
|
Reservation.date >= month_start,
|
|
)
|
|
)
|
|
)
|
|
count = result.scalar_one()
|
|
limit = PLAN_LIMITS[business.plan]
|
|
|
|
return UsageRead(
|
|
plan=business.plan,
|
|
reservations_this_month=count,
|
|
monthly_limit=limit,
|
|
is_unlimited=limit == -1,
|
|
)
|