another fix - once more
This commit is contained in:
@@ -21,17 +21,40 @@ class CreateReport:
|
||||
ubicacion: Optional[str] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Sends a create report message to RabbitMQ.
|
||||
The actual database save will be done by the consumer.
|
||||
Valida previamente:
|
||||
- Usuario existe
|
||||
- Descripción no está vacía
|
||||
- Tipo de reporte válido
|
||||
|
||||
Returns:
|
||||
Dictionary with status and message
|
||||
"""
|
||||
# Verify user exists (we still need to check this before queuing)
|
||||
user = self.user_repo.find_by_id(id_usuario)
|
||||
if not user:
|
||||
# Validación: descripción requerida
|
||||
if not descripcion or not descripcion.strip():
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Usuario con ID {id_usuario} no existe"
|
||||
"message": "La descripción del reporte es requerida"
|
||||
}
|
||||
|
||||
# Validación: tipo de reporte válido (1-5)
|
||||
if tipo_reporte < 1 or tipo_reporte > 5:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": "El tipo de reporte debe estar entre 1 y 5"
|
||||
}
|
||||
|
||||
# Validación: usuario existe (CRÍTICO)
|
||||
try:
|
||||
user = self.user_repo.find_by_id(id_usuario)
|
||||
if not user:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Usuario con ID {id_usuario} no existe"
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Error al validar usuario: {str(e)}"
|
||||
}
|
||||
|
||||
id_reporte = str(uuid4())
|
||||
@@ -43,7 +66,7 @@ class CreateReport:
|
||||
id_reporte=id_reporte,
|
||||
id_usuario=id_usuario,
|
||||
tipo_reporte=tipo_reporte,
|
||||
descripcion=descripcion,
|
||||
descripcion=descripcion.strip(),
|
||||
ubicacion=ubicacion,
|
||||
visibilidad=50.0, # Visibilidad inicial neutral
|
||||
fecha_creacion=fecha_creacion.isoformat()
|
||||
@@ -105,11 +128,27 @@ class UpdateReportVisibility:
|
||||
def execute(self, report_id: str, new_visibility: float, penalize_author: bool = False) -> Dict[str, Any]:
|
||||
"""
|
||||
Sends an update report visibility message to RabbitMQ.
|
||||
The actual database update will be done by the consumer.
|
||||
Valida previamente:
|
||||
- Reporte existe
|
||||
- Visibilidad en rango válido (0-100)
|
||||
|
||||
Returns:
|
||||
Dictionary with status and message
|
||||
"""
|
||||
# Validación: reporte existe
|
||||
try:
|
||||
report = self.repo.find_by_id(report_id)
|
||||
if not report:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Reporte con ID {report_id} no existe"
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Error al buscar reporte: {str(e)}"
|
||||
}
|
||||
|
||||
# Validar rango de visibilidad
|
||||
if new_visibility < 0 or new_visibility > 100:
|
||||
return {
|
||||
@@ -161,11 +200,26 @@ class DeleteReport:
|
||||
def execute(self, report_id: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Sends a delete report message to RabbitMQ.
|
||||
The actual database deletion will be done by the consumer.
|
||||
Valida previamente:
|
||||
- Reporte existe
|
||||
|
||||
Returns:
|
||||
Dictionary with status and message
|
||||
"""
|
||||
# Validación: reporte existe
|
||||
try:
|
||||
report = self.repo.find_by_id(report_id)
|
||||
if not report:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Reporte con ID {report_id} no existe"
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Error al buscar reporte: {str(e)}"
|
||||
}
|
||||
|
||||
# Create message object
|
||||
message = ReportMessage(
|
||||
event_type=ReportEventType.DELETE,
|
||||
|
||||
Reference in New Issue
Block a user