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/admin/__init__.py
Normal file
0
backend/app/modules/admin/__init__.py
Normal file
43
backend/app/modules/admin/router.py
Normal file
43
backend/app/modules/admin/router.py
Normal file
@ -0,0 +1,43 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.dependencies import require_admin
|
||||
from app.modules.admin import schemas, service
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/businesses", response_model=list[schemas.BusinessSummary])
|
||||
async def list_businesses(
|
||||
_=Depends(require_admin),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.list_businesses(db)
|
||||
|
||||
|
||||
@router.get("/businesses/{business_id}", response_model=schemas.BusinessSummary)
|
||||
async def get_business(
|
||||
business_id: int,
|
||||
_=Depends(require_admin),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_business(db, business_id)
|
||||
|
||||
|
||||
@router.patch("/businesses/{business_id}/status", response_model=schemas.BusinessSummary)
|
||||
async def update_status(
|
||||
business_id: int,
|
||||
body: schemas.StatusPatch,
|
||||
_=Depends(require_admin),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.update_business_status(db, business_id, body.status)
|
||||
|
||||
|
||||
@router.get("/stats", response_model=schemas.PlatformStats)
|
||||
async def get_stats(
|
||||
_=Depends(require_admin),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
return await service.get_platform_stats(db)
|
||||
21
backend/app/modules/admin/schemas.py
Normal file
21
backend/app/modules/admin/schemas.py
Normal file
@ -0,0 +1,21 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BusinessSummary(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
type: str
|
||||
status: str
|
||||
plan: str
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class StatusPatch(BaseModel):
|
||||
status: str
|
||||
|
||||
|
||||
class PlatformStats(BaseModel):
|
||||
total_businesses: int
|
||||
active_businesses: int
|
||||
total_reservations: int
|
||||
51
backend/app/modules/admin/service.py
Normal file
51
backend/app/modules/admin/service.py
Normal file
@ -0,0 +1,51 @@
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.modules.admin.schemas import BusinessSummary, PlatformStats
|
||||
from app.modules.business.models import Business
|
||||
from app.modules.reservations.models import Reservation
|
||||
|
||||
VALID_STATUSES = {"trial", "active", "suspended"}
|
||||
|
||||
|
||||
async def list_businesses(db: AsyncSession) -> list[Business]:
|
||||
result = await db.execute(select(Business).order_by(Business.created_at.desc()))
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def get_business(db: AsyncSession, business_id: int) -> Business:
|
||||
result = await db.execute(select(Business).where(Business.id == business_id))
|
||||
business = result.scalar_one_or_none()
|
||||
if not business:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Negocio no encontrado")
|
||||
return business
|
||||
|
||||
|
||||
async def update_business_status(db: AsyncSession, business_id: int, new_status: str) -> Business:
|
||||
if new_status not in VALID_STATUSES:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Estado inválido. Opciones: {', '.join(VALID_STATUSES)}",
|
||||
)
|
||||
business = await get_business(db, business_id)
|
||||
business.status = new_status
|
||||
await db.commit()
|
||||
await db.refresh(business)
|
||||
return business
|
||||
|
||||
|
||||
async def get_platform_stats(db: AsyncSession) -> PlatformStats:
|
||||
total = (await db.execute(select(func.count(Business.id)))).scalar_one()
|
||||
active = (
|
||||
await db.execute(
|
||||
select(func.count(Business.id)).where(Business.status == "active")
|
||||
)
|
||||
).scalar_one()
|
||||
reservations = (await db.execute(select(func.count(Reservation.id)))).scalar_one()
|
||||
|
||||
return PlatformStats(
|
||||
total_businesses=total,
|
||||
active_businesses=active,
|
||||
total_reservations=reservations,
|
||||
)
|
||||
Reference in New Issue
Block a user