feat: plantilla base workspace SaaS
Convierte el repositorio de Anexo76 en una plantilla limpia y reutilizable para nuevos proyectos del ecosistema Workspace de Aduanasoft. Cambios principales: - Elimina módulos específicos de Anexo76: a76, a24, sitar, public - Agrega módulo example/ con patrón CRUD de referencia (models/dto/service/routes) - Limpia migraciones Alembic: solo quedan las 6 de core (users, tenants, permissions) - Reemplaza todas las rutas del dashboard con stubs genéricos - Elimina lógica de negocio aduanera: shortcuts, CSV imports, permisos, catálogos - Simplifica variables de entorno: una sola WORKSPACE_URL deriva Hub y Keycloak - Agrega scripts/auth-mode.sh para alternar entre auth local y workspace - Configura docker-compose con nombres genéricos (app-*) - Corrige flujo SSO: elimina system-gate SCAF/SCAII que bloqueaba el login - Modo DEV_LOCAL_AUTH para desarrollo sin Keycloak ni Hub Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
48
backend/api/v1/modules/example/service.py
Normal file
48
backend/api/v1/modules/example/service.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import ItemCreate, ItemUpdate
|
||||
from .models import Item
|
||||
|
||||
|
||||
def get_items(db: Session, tenant_id: int, company_id: int) -> list[Item]:
|
||||
return (
|
||||
db.query(Item)
|
||||
.filter(Item.tenant_id == tenant_id, Item.company_id == company_id, Item.deleted_at.is_(None))
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
def get_item(db: Session, item_id: int, tenant_id: int, company_id: int) -> Item:
|
||||
item = (
|
||||
db.query(Item)
|
||||
.filter(Item.id == item_id, Item.tenant_id == tenant_id, Item.company_id == company_id, Item.deleted_at.is_(None))
|
||||
.first()
|
||||
)
|
||||
if not item:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Item no encontrado")
|
||||
return item
|
||||
|
||||
|
||||
def create_item(db: Session, payload: ItemCreate, tenant_id: int, company_id: int) -> Item:
|
||||
item = Item(**payload.model_dump(), tenant_id=tenant_id, company_id=company_id)
|
||||
db.add(item)
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return item
|
||||
|
||||
|
||||
def update_item(db: Session, item_id: int, payload: ItemUpdate, tenant_id: int, company_id: int) -> Item:
|
||||
item = get_item(db, item_id, tenant_id, company_id)
|
||||
for field, value in payload.model_dump(exclude_unset=True).items():
|
||||
setattr(item, field, value)
|
||||
db.commit()
|
||||
db.refresh(item)
|
||||
return item
|
||||
|
||||
|
||||
def delete_item(db: Session, item_id: int, tenant_id: int, company_id: int) -> None:
|
||||
item = get_item(db, item_id, tenant_id, company_id)
|
||||
from datetime import datetime, timezone
|
||||
item.deleted_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user