feat: añadir app general con LogService centralizado
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/pr-dev This commit looks good
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good

- Crear app/general con estructura estándar del proyecto:
  · utilidades/acciones.py → LogService.gestionar_log() (única fuente de logs)
  · utilidades/utils.py → get_client_ip()
  · utilidades/custom_errors.py → ValidationError, ExternalServiceError, NotFoundError
  · exception.py, request.py, serializers.py, validaciones/
- Registrar 'general' en INSTALLED_APPS y añadir general/ a urls.py
- Refactorizar promociones/views.py para usar LogService en lugar de Log directo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
juanjo
2026-04-16 16:50:53 +02:00
parent 91fc6900eb
commit 2f6564d9a6
19 changed files with 230 additions and 27 deletions

24
app/general/request.py Normal file
View File

@@ -0,0 +1,24 @@
import json
from django.http import JsonResponse
def parse_body(request):
"""
Parsea el body de la request como JSON.
Lanza ValueError si el body está vacío o no es JSON válido.
"""
raw = request.body
if not raw:
raise ValueError('El body de la petición está vacío.')
return json.loads(raw)
def build_error_response(message, status=400, data=None):
"""Construye una respuesta de error en el formato estándar del proyecto."""
body = {'data': data if data is not None else [], 'error': message}
return JsonResponse({'body': body, 'mensaje': message}, status=status, safe=False)
def build_success_response(data, status=200):
"""Construye una respuesta de éxito en el formato estándar del proyecto."""
return JsonResponse(data, status=status, safe=False)