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>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from fastapi import HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.modules.business.models import Business, BusinessConfig
|
|
from app.modules.business.schemas import BusinessConfigUpdate, BusinessUpdate
|
|
|
|
|
|
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(
|
|
db: AsyncSession, business_id: int, data: BusinessUpdate
|
|
) -> Business:
|
|
business = await get_business(db, business_id)
|
|
for field, value in data.model_dump(exclude_none=True).items():
|
|
setattr(business, field, value)
|
|
await db.commit()
|
|
await db.refresh(business)
|
|
return business
|
|
|
|
|
|
async def get_business_config(db: AsyncSession, business_id: int) -> BusinessConfig:
|
|
result = await db.execute(
|
|
select(BusinessConfig).where(BusinessConfig.business_id == business_id)
|
|
)
|
|
config = result.scalar_one_or_none()
|
|
if not config:
|
|
config = BusinessConfig(business_id=business_id)
|
|
db.add(config)
|
|
await db.commit()
|
|
await db.refresh(config)
|
|
return config
|
|
|
|
|
|
async def update_business_config(
|
|
db: AsyncSession, business_id: int, data: BusinessConfigUpdate
|
|
) -> BusinessConfig:
|
|
config = await get_business_config(db, business_id)
|
|
for field, value in data.model_dump(exclude_none=True).items():
|
|
setattr(config, field, value)
|
|
await db.commit()
|
|
await db.refresh(config)
|
|
return config
|