feat: initial commit — HermesMessages SaaS platform
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>
This commit is contained in:
0
backend/app/modules/billing/__init__.py
Normal file
0
backend/app/modules/billing/__init__.py
Normal file
33
backend/app/modules/billing/router.py
Normal file
33
backend/app/modules/billing/router.py
Normal file
@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.dependencies import get_current_business
|
||||
from app.modules.billing import schemas, service
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/plan", response_model=schemas.PlanRead)
|
||||
async def get_plan(
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_plan(db, business_id)
|
||||
|
||||
|
||||
@router.post("/upgrade", response_model=schemas.PlanRead)
|
||||
async def upgrade_plan(
|
||||
body: schemas.UpgradeRequest,
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.upgrade_plan(db, business_id, body.plan)
|
||||
|
||||
|
||||
@router.get("/usage", response_model=schemas.UsageRead)
|
||||
async def get_usage(
|
||||
business_id: int = Depends(get_current_business),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_usage(db, business_id)
|
||||
25
backend/app/modules/billing/schemas.py
Normal file
25
backend/app/modules/billing/schemas.py
Normal file
@ -0,0 +1,25 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
PLAN_LIMITS = {
|
||||
"free": 50,
|
||||
"basic": 500,
|
||||
"pro": -1, # ilimitado
|
||||
}
|
||||
|
||||
|
||||
class PlanRead(BaseModel):
|
||||
plan: str
|
||||
status: str
|
||||
monthly_limit: int
|
||||
is_unlimited: bool
|
||||
|
||||
|
||||
class UpgradeRequest(BaseModel):
|
||||
plan: str
|
||||
|
||||
|
||||
class UsageRead(BaseModel):
|
||||
plan: str
|
||||
reservations_this_month: int
|
||||
monthly_limit: int
|
||||
is_unlimited: bool
|
||||
59
backend/app/modules/billing/service.py
Normal file
59
backend/app/modules/billing/service.py
Normal file
@ -0,0 +1,59 @@
|
||||
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,
|
||||
)
|
||||
Reference in New Issue
Block a user