tematicas por tipo de bot

This commit is contained in:
2026-04-29 09:39:56 -05:00
parent f548a2d9bd
commit dcd77a3982
14 changed files with 1284 additions and 83 deletions

View File

@ -1,11 +1,13 @@
from datetime import date, time
from sqlalchemy import (
Boolean,
Column,
Date,
Enum,
ForeignKey,
Integer,
Numeric,
String,
Time,
func,
@ -41,6 +43,8 @@ class Business(Base):
users = relationship("User", back_populates="business", cascade="all, delete-orphan")
config = relationship("BusinessConfig", back_populates="business", uselist=False)
reservations = relationship("Reservation", back_populates="business")
table_types = relationship("TableType", back_populates="business", cascade="all, delete-orphan")
services = relationship("Service", back_populates="business", cascade="all, delete-orphan")
class BusinessConfig(Base):
@ -63,3 +67,33 @@ class BusinessConfig(Base):
welcome_message = Column(String, nullable=True)
business = relationship("Business", back_populates="config")
class TableType(Base):
__tablename__ = "table_types"
id = Column(Integer, primary_key=True, index=True)
business_id = Column(
Integer, ForeignKey("businesses.id", ondelete="CASCADE"), nullable=False, index=True
)
capacity = Column(Integer, nullable=False)
quantity = Column(Integer, nullable=False)
label = Column(String, nullable=True)
business = relationship("Business", back_populates="table_types")
class Service(Base):
__tablename__ = "services"
id = Column(Integer, primary_key=True, index=True)
business_id = Column(
Integer, ForeignKey("businesses.id", ondelete="CASCADE"), nullable=False, index=True
)
name = Column(String, nullable=False)
description = Column(String, nullable=True)
price = Column(Numeric(10, 2), nullable=True)
duration_minutes = Column(Integer, nullable=True)
is_active = Column(Boolean, nullable=False, default=True)
business = relationship("Business", back_populates="services")

View File

@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Response, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
@ -40,3 +40,77 @@ async def update_my_config(
db: AsyncSession = Depends(get_db),
):
return await service.update_business_config(db, business_id, body)
@router.get("/me/tables", response_model=list[schemas.TableTypeRead])
async def list_tables(
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.list_table_types(db, business_id)
@router.post("/me/tables", response_model=schemas.TableTypeRead, status_code=201)
async def create_table(
body: schemas.TableTypeCreate,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.create_table_type(db, business_id, body)
@router.put("/me/tables/{table_id}", response_model=schemas.TableTypeRead)
async def update_table(
table_id: int,
body: schemas.TableTypeUpdate,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.update_table_type(db, business_id, table_id, body)
@router.delete("/me/tables/{table_id}", status_code=204)
async def delete_table(
table_id: int,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
await service.delete_table_type(db, business_id, table_id)
return Response(status_code=204)
@router.get("/me/services", response_model=list[schemas.ServiceRead])
async def list_services(
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.list_services(db, business_id)
@router.post("/me/services", response_model=schemas.ServiceRead, status_code=201)
async def create_service(
body: schemas.ServiceCreate,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.create_service(db, business_id, body)
@router.put("/me/services/{service_id}", response_model=schemas.ServiceRead)
async def update_service(
service_id: int,
body: schemas.ServiceUpdate,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
return await service.update_service(db, business_id, service_id, body)
@router.delete("/me/services/{service_id}", status_code=204)
async def delete_service(
service_id: int,
business_id: int = Depends(get_current_business),
db: AsyncSession = Depends(get_db),
):
await service.delete_service(db, business_id, service_id)
return Response(status_code=204)

View File

@ -46,3 +46,50 @@ class BusinessConfigUpdate(BaseModel):
assistant_name: str | None = None
tone: str | None = None
welcome_message: str | None = None
class TableTypeCreate(BaseModel):
capacity: int
quantity: int
label: str | None = None
class TableTypeUpdate(BaseModel):
capacity: int | None = None
quantity: int | None = None
label: str | None = None
class TableTypeRead(BaseModel):
id: int
capacity: int
quantity: int
label: str | None
model_config = {"from_attributes": True}
class ServiceCreate(BaseModel):
name: str
description: str | None = None
price: float | None = None
duration_minutes: int | None = None
class ServiceUpdate(BaseModel):
name: str | None = None
description: str | None = None
price: float | None = None
duration_minutes: int | None = None
is_active: bool | None = None
class ServiceRead(BaseModel):
id: int
name: str
description: str | None
price: float | None
duration_minutes: int | None
is_active: bool
model_config = {"from_attributes": True}

View File

@ -2,8 +2,15 @@ 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
from app.modules.business.models import Business, BusinessConfig, Service, TableType
from app.modules.business.schemas import (
BusinessConfigUpdate,
BusinessUpdate,
ServiceCreate,
ServiceUpdate,
TableTypeCreate,
TableTypeUpdate,
)
async def get_business(db: AsyncSession, business_id: int) -> Business:
@ -47,3 +54,91 @@ async def update_business_config(
await db.commit()
await db.refresh(config)
return config
async def list_table_types(db: AsyncSession, business_id: int) -> list[TableType]:
result = await db.execute(
select(TableType)
.where(TableType.business_id == business_id)
.order_by(TableType.capacity)
)
return list(result.scalars().all())
async def create_table_type(db: AsyncSession, business_id: int, data: TableTypeCreate) -> TableType:
table = TableType(business_id=business_id, **data.model_dump())
db.add(table)
await db.commit()
await db.refresh(table)
return table
async def update_table_type(
db: AsyncSession, business_id: int, table_id: int, data: TableTypeUpdate
) -> TableType:
result = await db.execute(
select(TableType).where(TableType.id == table_id, TableType.business_id == business_id)
)
table = result.scalar_one_or_none()
if not table:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Tipo de mesa no encontrado")
for field, value in data.model_dump(exclude_none=True).items():
setattr(table, field, value)
await db.commit()
await db.refresh(table)
return table
async def delete_table_type(db: AsyncSession, business_id: int, table_id: int) -> None:
result = await db.execute(
select(TableType).where(TableType.id == table_id, TableType.business_id == business_id)
)
table = result.scalar_one_or_none()
if not table:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Tipo de mesa no encontrado")
await db.delete(table)
await db.commit()
async def list_services(db: AsyncSession, business_id: int) -> list[Service]:
result = await db.execute(
select(Service)
.where(Service.business_id == business_id)
.order_by(Service.name)
)
return list(result.scalars().all())
async def create_service(db: AsyncSession, business_id: int, data: ServiceCreate) -> Service:
service = Service(business_id=business_id, **data.model_dump())
db.add(service)
await db.commit()
await db.refresh(service)
return service
async def update_service(
db: AsyncSession, business_id: int, service_id: int, data: ServiceUpdate
) -> Service:
result = await db.execute(
select(Service).where(Service.id == service_id, Service.business_id == business_id)
)
service = result.scalar_one_or_none()
if not service:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Servicio no encontrado")
for field, value in data.model_dump(exclude_none=True).items():
setattr(service, field, value)
await db.commit()
await db.refresh(service)
return service
async def delete_service(db: AsyncSession, business_id: int, service_id: int) -> None:
result = await db.execute(
select(Service).where(Service.id == service_id, Service.business_id == business_id)
)
service = result.scalar_one_or_none()
if not service:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Servicio no encontrado")
await db.delete(service)
await db.commit()