Compare commits
20 Commits
252e176e9d
...
pre-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a53cd3918 | ||
|
|
35e1d38859 | ||
|
|
a064895689 | ||
|
|
05e95f8880 | ||
|
|
af38d88876 | ||
|
|
02fa6247f1 | ||
|
|
428b745700 | ||
|
|
f6892b2166 | ||
|
|
d2c91d5196 | ||
|
|
d735d73322 | ||
|
|
197cff011f | ||
|
|
590e18e994 | ||
|
|
c692ce2a61 | ||
|
|
152e9c14ef | ||
|
|
99de5f06b5 | ||
|
|
d7a84a4dfa | ||
|
|
fbc5f0f6c4 | ||
|
|
cac00a4f8c | ||
|
|
a17f00bad2 | ||
|
|
b8c3e03348 |
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,2 +1,5 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Shell scripts: forzar LF siempre (evita CRLF en Windows que rompe Docker)
|
||||
*.sh text eol=lf
|
||||
|
||||
@@ -80,10 +80,17 @@ class MiVista(APIView):
|
||||
pre-dev → dev → master
|
||||
```
|
||||
|
||||
- `pre-dev`: desarrollo activo
|
||||
- `pre-dev`: desarrollo activo — aquí entran todos los cambios
|
||||
- `dev`: validación previa a producción
|
||||
- `master`: producción estable
|
||||
- Merges siempre con `--no-ff`
|
||||
- **NUNCA** propagar en sentido inverso (master → dev o dev → pre-dev)
|
||||
- Secuencia correcta:
|
||||
```bash
|
||||
git checkout pre-dev && git merge <mi-cambio> --no-ff
|
||||
git checkout dev && git merge pre-dev --no-ff && git push origin dev
|
||||
git checkout master && git merge dev --no-ff && git push origin master
|
||||
```
|
||||
|
||||
## Estructura de app Django
|
||||
|
||||
|
||||
14
README.md
14
README.md
@@ -140,9 +140,11 @@ python manage.py migrate <app_name> zero
|
||||
|
||||
---
|
||||
|
||||
## Docker — Producción
|
||||
## Docker — Local y Producción
|
||||
|
||||
```bash
|
||||
cd deployments
|
||||
|
||||
# Construir e iniciar
|
||||
docker-compose up --build -d
|
||||
|
||||
@@ -158,6 +160,16 @@ docker-compose down -v
|
||||
|
||||
El contenedor expone el puerto **8000**.
|
||||
|
||||
### Crear superusuario (primera vez con Docker)
|
||||
|
||||
Una vez los contenedores estén corriendo:
|
||||
|
||||
```bash
|
||||
docker-compose exec web sh -c "cd /app/app && python manage.py createsuperuser"
|
||||
```
|
||||
|
||||
Introduce usuario, email y contraseña cuando lo pida. Estas credenciales son las que usarás para entrar en el panel web (`web_interno`) y en `/admin/`.
|
||||
|
||||
Para producción con PostgreSQL, asegúrate de que `.env` tenga `DB_HOST` apuntando al host correcto (puede ser el nombre del servicio en la red Docker).
|
||||
|
||||
---
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
from django.core.asgi import get_asgi_application
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_hub_dispatcher.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_config.settings')
|
||||
application = get_asgi_application()
|
||||
@@ -74,7 +74,7 @@ MIDDLEWARE = [
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'api_hub_dispatcher.urls'
|
||||
ROOT_URLCONF = 'api_config.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
@@ -92,7 +92,7 @@ TEMPLATES = [
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'api_hub_dispatcher.wsgi.application'
|
||||
WSGI_APPLICATION = 'api_config.wsgi.application'
|
||||
|
||||
# 3. DATABASE
|
||||
# En producción (cuando DB_HOST está definido) usa PostgreSQL.
|
||||
@@ -175,6 +175,11 @@ LOGGING = {
|
||||
},
|
||||
}
|
||||
|
||||
# --- URLs de APIs internas (via red Docker saas_network) ---
|
||||
API_BACKOFFICE = os.getenv('API_BACKOFFICE', 'http://api_backoffice:8001')
|
||||
API_COMUNICACIONES = os.getenv('API_COMUNICACIONES', 'http://api_comunicaciones:8002')
|
||||
API_DOCUMENTACION = os.getenv('API_DOCUMENTACION', 'http://api_documentacion:8003')
|
||||
|
||||
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
||||
|
||||
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
||||
|
||||
@@ -2,6 +2,6 @@ import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
# Este es el enlace con tus configuraciones
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_hub_dispatcher.settings')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api_config.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
60
app/common/http_client.py
Normal file
60
app/common/http_client.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import urllib.request
|
||||
import json
|
||||
import os
|
||||
|
||||
BACKOFFICE_URL = os.getenv('BACKOFFICE_URL', 'http://django_app_backoffice:8000')
|
||||
COMUNICACIONES_URL = os.getenv('COMUNICACIONES_URL', 'http://django_app_comunicaciones:8000')
|
||||
DOCUMENTACION_URL = os.getenv('DOCUMENTACION_URL', 'http://django_app_documentacion:8000')
|
||||
|
||||
|
||||
def _post(url, payload):
|
||||
data = json.dumps(payload).encode('utf-8')
|
||||
req = urllib.request.Request(
|
||||
url, data=data,
|
||||
headers={'Content-Type': 'application/json'},
|
||||
method='POST'
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
return json.loads(resp.read())
|
||||
|
||||
|
||||
# --- Backoffice ---
|
||||
def backoffice_obtener_usuario(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/usuarios/obtener/', params)
|
||||
|
||||
def backoffice_crear_usuario(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/usuarios/guardar/', params)
|
||||
|
||||
def backoffice_obtener_cliente(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/clientes/obtener/', params)
|
||||
|
||||
def backoffice_crear_cliente(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/clientes/guardar/', params)
|
||||
|
||||
def backoffice_obtener_contrato(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/contratos/obtener/', params)
|
||||
|
||||
def backoffice_crear_contrato(params):
|
||||
return _post(f'{BACKOFFICE_URL}/api/contratos/guardar/', params)
|
||||
|
||||
|
||||
# --- Comunicaciones ---
|
||||
def comunicaciones_enviar_email(params):
|
||||
return _post(f'{COMUNICACIONES_URL}/api/email/enviar/', params)
|
||||
|
||||
def comunicaciones_enviar_sms(params):
|
||||
return _post(f'{COMUNICACIONES_URL}/api/sms/enviar/', params)
|
||||
|
||||
def comunicaciones_registrar_webhook(params):
|
||||
return _post(f'{COMUNICACIONES_URL}/api/webhooks/registrar/', params)
|
||||
|
||||
|
||||
# --- Documentacion ---
|
||||
def documentacion_generar_pdf(params):
|
||||
return _post(f'{DOCUMENTACION_URL}/api/generation/pdf/', params)
|
||||
|
||||
def documentacion_obtener_template(params):
|
||||
return _post(f'{DOCUMENTACION_URL}/api/templates/obtener/', params)
|
||||
|
||||
def documentacion_guardar_documento(params):
|
||||
return _post(f'{DOCUMENTACION_URL}/api/storage/guardar/', params)
|
||||
100
app/general/request_api.py
Normal file
100
app/general/request_api.py
Normal file
@@ -0,0 +1,100 @@
|
||||
import json
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Request_API:
|
||||
"""Dispatcher de llamadas HTTP internas hacia las APIs especializadas."""
|
||||
|
||||
def _post(self, base_url, url_path, data):
|
||||
url = base_url.rstrip('/') + '/' + url_path.lstrip('/')
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers, timeout=30)
|
||||
return response.json(), response.status_code
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# api_backoffice #
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def backoffice_get_parameterized(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/get_parameterized/', data)
|
||||
|
||||
def backoffice_get_dataComplex(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/get_dataComplex/', data)
|
||||
|
||||
def backoffice_set_parameterized(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/set_parameterized/', data)
|
||||
|
||||
def backoffice_set_data2(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/set_data2/', data)
|
||||
|
||||
def backoffice_set_data_batch(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/set_data_batch/', data)
|
||||
|
||||
def backoffice_get_BBDD(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/get_BBDD/', data)
|
||||
|
||||
def backoffice_set_BBDD(self, data):
|
||||
return self._post(settings.API_BACKOFFICE, 'api/general/set_BBDD/', data)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# api_comunicaciones #
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def comunicaciones_get_parameterized(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/get_parameterized/', data)
|
||||
|
||||
def comunicaciones_get_dataComplex(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/get_dataComplex/', data)
|
||||
|
||||
def comunicaciones_set_parameterized(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/set_parameterized/', data)
|
||||
|
||||
def comunicaciones_set_data2(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/set_data2/', data)
|
||||
|
||||
def comunicaciones_set_data_batch(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/set_data_batch/', data)
|
||||
|
||||
def comunicaciones_get_BBDD(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/get_BBDD/', data)
|
||||
|
||||
def comunicaciones_set_BBDD(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/general/set_BBDD/', data)
|
||||
|
||||
def comunicaciones_enviar_email(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/email/enviar/', data)
|
||||
|
||||
def comunicaciones_enviar_sms(self, data):
|
||||
return self._post(settings.API_COMUNICACIONES, 'api/sms/enviar/', data)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# api_documentacion #
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def documentacion_get_parameterized(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/get_parameterized/', data)
|
||||
|
||||
def documentacion_get_dataComplex(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/get_dataComplex/', data)
|
||||
|
||||
def documentacion_set_parameterized(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/set_parameterized/', data)
|
||||
|
||||
def documentacion_set_data2(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/set_data2/', data)
|
||||
|
||||
def documentacion_set_data_batch(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/set_data_batch/', data)
|
||||
|
||||
def documentacion_get_BBDD(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/get_BBDD/', data)
|
||||
|
||||
def documentacion_set_BBDD(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/general/set_BBDD/', data)
|
||||
|
||||
def documentacion_generar_pdf(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/generation/pdf/', data)
|
||||
|
||||
def documentacion_guardar(self, data):
|
||||
return self._post(settings.API_DOCUMENTACION, 'api/storage/guardar/', data)
|
||||
26
app/promociones/migrations/0001_initial.py
Normal file
26
app/promociones/migrations/0001_initial.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Promocion',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('nombre', models.CharField(max_length=255)),
|
||||
('fecha_inicio', models.DateField(blank=True, null=True)),
|
||||
('fecha_modificacion', models.DateField(blank=True, null=True)),
|
||||
('descripcion', models.TextField(blank=True, null=True)),
|
||||
('activo', models.BooleanField(default=True)),
|
||||
('categoria_id', models.IntegerField(blank=True, null=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'promociones',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -5,3 +5,4 @@ python-dotenv==1.0.1
|
||||
djangorestframework
|
||||
django-cors-headers
|
||||
djangorestframework-simplejwt
|
||||
requests==2.32.3
|
||||
15
deployments/Makefile
Normal file
15
deployments/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
NETWORK = saas_network
|
||||
|
||||
.PHONY: network up down logs
|
||||
|
||||
network:
|
||||
docker network inspect $(NETWORK) >/dev/null 2>&1 || docker network create $(NETWORK)
|
||||
|
||||
up: network
|
||||
docker compose up --build -d
|
||||
|
||||
down:
|
||||
docker compose down
|
||||
|
||||
logs:
|
||||
docker compose logs -f
|
||||
@@ -27,7 +27,7 @@ services:
|
||||
container_name: ${APP_CONTAINER_NAME:-django_core_app}
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ../.env
|
||||
- .env
|
||||
environment:
|
||||
- DB_HOST=db
|
||||
- DB_PORT=5432
|
||||
@@ -36,6 +36,13 @@ services:
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- default
|
||||
- saas_network
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
networks:
|
||||
saas_network:
|
||||
name: saas_network
|
||||
|
||||
@@ -5,3 +5,4 @@ python-dotenv==1.0.1
|
||||
djangorestframework
|
||||
django-cors-headers
|
||||
djangorestframework-simplejwt
|
||||
requests==2.32.3
|
||||
11
environments/DEV.postman_environment.json
Normal file
11
environments/DEV.postman_environment.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "x8jh10qysfo",
|
||||
"name": "DEV",
|
||||
"values": [
|
||||
{ "key": "base_url", "value": "https://dev.v-encore-lab.com", "type": "default", "enabled": true },
|
||||
{ "key": "username", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "password", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "access_token", "value": "", "type": "default", "enabled": true }
|
||||
],
|
||||
"_postman_variable_scope": "environment"
|
||||
}
|
||||
11
environments/LOCAL.postman_environment.json
Normal file
11
environments/LOCAL.postman_environment.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "ftt19d5vxuj",
|
||||
"name": "LOCAL",
|
||||
"values": [
|
||||
{ "key": "base_url", "value": "http://localhost:8000", "type": "default", "enabled": true },
|
||||
{ "key": "username", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "password", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "access_token", "value": "", "type": "default", "enabled": true }
|
||||
],
|
||||
"_postman_variable_scope": "environment"
|
||||
}
|
||||
11
environments/PROD.postman_environment.json
Normal file
11
environments/PROD.postman_environment.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "3ckrklvkf27",
|
||||
"name": "PROD",
|
||||
"values": [
|
||||
{ "key": "base_url", "value": "https://v-encore-lab.com", "type": "default", "enabled": true },
|
||||
{ "key": "username", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "password", "value": "admin", "type": "default", "enabled": true },
|
||||
{ "key": "access_token", "value": "", "type": "default", "enabled": true }
|
||||
],
|
||||
"_postman_variable_scope": "environment"
|
||||
}
|
||||
@@ -6,31 +6,8 @@
|
||||
"_postman_id": "django-core-base-collection"
|
||||
},
|
||||
"variable": [
|
||||
{
|
||||
"key": "base_url",
|
||||
"value": "http://localhost:8000",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "access_token",
|
||||
"value": "",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "refresh_token",
|
||||
"value": "",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "username",
|
||||
"value": "admin",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "password",
|
||||
"value": "admin",
|
||||
"type": "string"
|
||||
}
|
||||
{ "key": "access_token", "value": "", "type": "string" },
|
||||
{ "key": "refresh_token", "value": "", "type": "string" }
|
||||
],
|
||||
"item": [
|
||||
{
|
||||
@@ -51,6 +28,29 @@
|
||||
"}"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "postrequest",
|
||||
"script": {
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"// Comprobamos si la respuesta es exitosa",
|
||||
"if (pw.response.status === 200) {",
|
||||
" // Si el body ya es un objeto no hace falta JSON.parse",
|
||||
" const body = typeof pw.response.body === 'string'",
|
||||
" ? JSON.parse(pw.response.body)",
|
||||
" : pw.response.body;",
|
||||
"",
|
||||
" if (body.access) {",
|
||||
" // Guardamos el token en el entorno actual",
|
||||
" pw.env.set(\"access_token\", body.access);",
|
||||
" console.log(\"✅ Token guardado correctamente\");",
|
||||
" } else {",
|
||||
" console.log(\"❌ No se encontró el campo 'access' en la respuesta\");",
|
||||
" }",
|
||||
"}"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
@@ -77,10 +77,13 @@
|
||||
{
|
||||
"name": "Obtener Promoción",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/json" },
|
||||
{ "key": "Authorization", "value": "Bearer {{access_token}}" }
|
||||
{ "key": "Content-Type", "value": "application/json" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
@@ -101,10 +104,13 @@
|
||||
{
|
||||
"name": "Ejecutar Automatizaciones",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/json" },
|
||||
{ "key": "Authorization", "value": "Bearer {{access_token}}" }
|
||||
{ "key": "Content-Type", "value": "application/json" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
@@ -120,10 +126,13 @@
|
||||
{
|
||||
"name": "Historial de Ejecuciones",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/json" },
|
||||
{ "key": "Authorization", "value": "Bearer {{access_token}}" }
|
||||
{ "key": "Content-Type", "value": "application/json" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
@@ -139,10 +148,13 @@
|
||||
{
|
||||
"name": "Estado del Módulo",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [{ "key": "token", "value": "{{access_token}}", "type": "string" }]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{ "key": "Content-Type", "value": "application/json" },
|
||||
{ "key": "Authorization", "value": "Bearer {{access_token}}" }
|
||||
{ "key": "Content-Type", "value": "application/json" }
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
|
||||
Reference in New Issue
Block a user