From fbec20138ae2e89c5b392a86a63f21aa790a21f8 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:24:58 -0500 Subject: [PATCH 1/8] feat(api): add PoiDetalleAdminDto --- services/api/DTOs/PoiDetalleAdminDto.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 services/api/DTOs/PoiDetalleAdminDto.cs diff --git a/services/api/DTOs/PoiDetalleAdminDto.cs b/services/api/DTOs/PoiDetalleAdminDto.cs new file mode 100644 index 0000000..0bdf9b2 --- /dev/null +++ b/services/api/DTOs/PoiDetalleAdminDto.cs @@ -0,0 +1,10 @@ +namespace TourVirtualUTB.Api.DTOs; + +/// +/// Detalle de un POI para el panel de administración: incluye inactivos, +/// medios y escenas asociadas. +/// +public sealed record PoiDetalleAdminDto( + PoiDto poi, + IReadOnlyList medios, + IReadOnlyList escenas); From 7198c6c66a9ac2b7eb30ac2a8a3c1c2a72a397b1 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:00 -0500 Subject: [PATCH 2/8] feat(api): add EliminarEscenaResultado enum --- services/api/Services/EliminarEscenaResultado.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 services/api/Services/EliminarEscenaResultado.cs diff --git a/services/api/Services/EliminarEscenaResultado.cs b/services/api/Services/EliminarEscenaResultado.cs new file mode 100644 index 0000000..8ebf2e6 --- /dev/null +++ b/services/api/Services/EliminarEscenaResultado.cs @@ -0,0 +1,13 @@ +namespace TourVirtualUTB.Api.Services; + +/// Resultado de intentar borrar una escena. +public enum EliminarEscenaResultado +{ + Eliminada, + NoExiste, + /// + /// Hay hotspots de otras escenas que apuntan a esta como destino + /// (FK Restrict en EscenaDestinoId). + /// + EnUsoComoDestino +} From b0a4b2eb278254f96a3f435747cf92cb5941dfa4 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:07 -0500 Subject: [PATCH 3/8] feat(api): ObtenerPoiAdminPorIdAsync y EliminarEscenaResultado en interfaz --- services/api/Services/IContenidoService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/api/Services/IContenidoService.cs b/services/api/Services/IContenidoService.cs index 0f5a81d..ae1c850 100644 --- a/services/api/Services/IContenidoService.cs +++ b/services/api/Services/IContenidoService.cs @@ -8,6 +8,8 @@ public interface IContenidoService Task> ObtenerPoisAsync(int lugarId, Audiencia audiencia); Task ObtenerRecorridoAsync(int lugarId, Audiencia audiencia); Task ObtenerPoiPorIdAsync(int poiId, Audiencia audiencia); + /// Detalle admin: POI activo o inactivo, con medios y escenas. + Task ObtenerPoiAdminPorIdAsync(int poiId); Task ObtenerRutaActivaAsync(int lugarId, Audiencia audiencia); Task ObtenerRutaMapaLugarAsync(int lugarId); Task ActualizarMapaLugarAsync(int lugarId, string rutaS3); @@ -22,7 +24,7 @@ public interface IContenidoService // Escenas Task CrearEscenaAsync(CrearEscenaRequest request); Task ActualizarEscenaAsync(int id, ActualizarEscenaRequest request); - Task EliminarEscenaAsync(int id); + Task EliminarEscenaAsync(int id); // Hotspots Task CrearHotspotAsync(CrearHotspotRequest request); From 7194a36c90e1b87df4f3ee4ec6e1d6a3e9d4d4e9 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:09 -0500 Subject: [PATCH 4/8] feat(api): GET /api/admin/pois/{id} con detalle y escenas --- services/api/Controllers/AdminPoisController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/api/Controllers/AdminPoisController.cs b/services/api/Controllers/AdminPoisController.cs index 162860c..cbd01f1 100644 --- a/services/api/Controllers/AdminPoisController.cs +++ b/services/api/Controllers/AdminPoisController.cs @@ -9,6 +9,17 @@ namespace TourVirtualUTB.Api.Controllers; [RequiereClaveAdmin] public class AdminPoisController(IContenidoService contenidoService) : ControllerBase { + /// + /// Detalle de un POI (activo o inactivo) con medios y escenas. + /// + [HttpGet("{id:int}")] + public async Task> ObtenerPoiAdmin(int id) + { + var detalle = await contenidoService.ObtenerPoiAdminPorIdAsync(id); + if (detalle is null) return NotFound("El punto de interés no existe."); + return Ok(detalle); + } + [HttpPost] public async Task> CrearPoi([FromBody] CrearPoiRequest request) { From 84ed207b3a6a52e6e2b919927d70f905056d8f10 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:10 -0500 Subject: [PATCH 5/8] =?UTF-8?q?fix(api):=20DELETE=20escena=20responde=2040?= =?UTF-8?q?9=20si=20est=C3=A1=20enlazada=20como=20destino?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/Controllers/AdminEscenasController.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/api/Controllers/AdminEscenasController.cs b/services/api/Controllers/AdminEscenasController.cs index c35bb33..c52d789 100644 --- a/services/api/Controllers/AdminEscenasController.cs +++ b/services/api/Controllers/AdminEscenasController.cs @@ -32,10 +32,20 @@ public async Task> ActualizarEscena(int id, [FromBody] A [HttpDelete("{id:int}")] public async Task EliminarEscena(int id) { - var eliminado = await contenidoService.EliminarEscenaAsync(id); - if (!eliminado) return NotFound("La escena no existe."); + var resultado = await contenidoService.EliminarEscenaAsync(id); - return NoContent(); + return resultado switch + { + EliminarEscenaResultado.NoExiste => + NotFound("La escena no existe."), + EliminarEscenaResultado.EnUsoComoDestino => + Conflict(new + { + mensaje = "No se puede eliminar la escena porque está enlazada como destino desde otra(s) escena(s). Elimina o reasigna esos hotspots primero.", + codigo = "escena_en_uso" + }), + _ => NoContent() + }; } /// From 5b09e8c5efb6d2fedb15f5758b9b8934f36d0466 Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:16 -0500 Subject: [PATCH 6/8] feat(api): implementar ObtenerPoiAdminPorIdAsync y chequeo de hotspots al borrar escena --- services/api/Services/ContenidoService.cs | 55 +++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/services/api/Services/ContenidoService.cs b/services/api/Services/ContenidoService.cs index 65dfe1e..8aa91f6 100644 --- a/services/api/Services/ContenidoService.cs +++ b/services/api/Services/ContenidoService.cs @@ -94,6 +94,50 @@ public async Task> ObtenerPoisAsync(int lugarId, Audiencia return new PoiDetalleDto(Dto.Poi(poi), medios.Select(Dto.Medio).ToList()); } + /// + /// Detalle para el panel: funciona con POIs activos e inactivos y + /// incluye las escenas del POI (además de los medios). + /// + public async Task ObtenerPoiAdminPorIdAsync(int poiId) + { + var poi = await db.Pois.AsNoTracking() + .Include(p => p.EscenaPrincipal) + .FirstOrDefaultAsync(p => p.Id == poiId); + + if (poi is null) return null; + + var medios = await db.Medios.AsNoTracking() + .Where(m => m.PoiId == poiId) + .OrderBy(m => m.Orden) + .ToListAsync(); + + var escenas = await db.Escenas.AsNoTracking() + .Where(e => e.PoiId == poiId) + .OrderBy(e => e.Orden) + .ToListAsync(); + + foreach (var medio in medios) + { + if (!string.IsNullOrEmpty(medio.Url)) + medio.Url = await almacenamiento.ObtenerUrlFirmadaAsync(medio.Url, TimeSpan.FromHours(2)); + if (!string.IsNullOrEmpty(medio.SubtitulosUrl)) + medio.SubtitulosUrl = await almacenamiento.ObtenerUrlFirmadaAsync(medio.SubtitulosUrl, TimeSpan.FromHours(2)); + } + + foreach (var escena in escenas) + { + if (!string.IsNullOrEmpty(escena.ImagenUrl)) + escena.ImagenUrl = await almacenamiento.ObtenerUrlFirmadaAsync(escena.ImagenUrl, TimeSpan.FromHours(2)); + if (!string.IsNullOrEmpty(escena.ImagenUrlBaja)) + escena.ImagenUrlBaja = await almacenamiento.ObtenerUrlFirmadaAsync(escena.ImagenUrlBaja, TimeSpan.FromHours(2)); + } + + return new PoiDetalleAdminDto( + Dto.Poi(poi), + medios.Select(Dto.Medio).ToList(), + escenas.Select(Dto.Escena).ToList()); + } + // Una escena sin panorámica no hace parada: la app trata como parada a todo // POI con escena_principal_id y ofrecería un 360 que no abre. Solo cambia la // respuesta (el POI viene sin seguimiento); en la base la escena sigue asignada. @@ -221,14 +265,19 @@ public async Task CrearEscenaAsync(CrearEscenaRequest request) return Dto.Escena(escena); } - public async Task EliminarEscenaAsync(int id) + public async Task EliminarEscenaAsync(int id) { var escena = await db.Escenas.FindAsync(id); - if (escena == null) return false; + if (escena == null) return EliminarEscenaResultado.NoExiste; + + // Hotspots de otras escenas que la usan como destino (OnDelete Restrict). + var referenciada = await db.Hotspots.AnyAsync(h => h.EscenaDestinoId == id); + if (referenciada) + return EliminarEscenaResultado.EnUsoComoDestino; db.Escenas.Remove(escena); await db.SaveChangesAsync(); - return true; + return EliminarEscenaResultado.Eliminada; } // --- MEDIOS (Multimedia) --- From 18a972212ee62678987f7db3c56834f989b40b5b Mon Sep 17 00:00:00 2001 From: Kevin Jose Guerrero Hincapie <92352993+HKevinGuerrero@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:25:18 -0500 Subject: [PATCH 7/8] docs(api): documentar GET admin POI y 409 en DELETE escena --- packages/contracts/openapi.yaml | 62 +++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/packages/contracts/openapi.yaml b/packages/contracts/openapi.yaml index 189cc12..20b1f0b 100644 --- a/packages/contracts/openapi.yaml +++ b/packages/contracts/openapi.yaml @@ -72,6 +72,10 @@ paths: delete: tags: - AdminEscenas + summary: Elimina una escena + description: | + Si la escena es destino de hotspots de otras escenas, responde 409 + en lugar de fallar con 500 por la restricción FK. parameters: - name: id in: path @@ -80,8 +84,22 @@ paths: type: integer format: int32 responses: - '200': - description: OK + '204': + description: Escena eliminada + '404': + description: La escena no existe + '409': + description: Escena enlazada como destino desde otros hotspots + content: + application/json: + schema: + type: object + properties: + mensaje: + type: string + codigo: + type: string + example: escena_en_uso '/api/admin/escenas/{id}/imagen': post: tags: @@ -622,6 +640,29 @@ paths: schema: $ref: '#/components/schemas/PoiDto' '/api/admin/pois/{id}': + get: + tags: + - AdminPois + summary: Detalle de un POI (activo o inactivo) con medios y escenas + description: | + A diferencia de GET /api/pois/{poiId}, este endpoint no filtra por + activo ni por audiencia e incluye las escenas del POI. + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int32 + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/PoiDetalleAdminDto' + '404': + description: El punto de interés no existe put: tags: - AdminPois @@ -1652,6 +1693,23 @@ components: $ref: '#/components/schemas/Medio' nullable: true additionalProperties: false + PoiDetalleAdminDto: + type: object + description: Detalle de POI para el panel (incluye inactivos, medios y escenas). + properties: + poi: + $ref: '#/components/schemas/PoiDto' + medios: + type: array + items: + $ref: '#/components/schemas/MedioDto' + nullable: true + escenas: + type: array + items: + $ref: '#/components/schemas/EscenaDto' + nullable: true + additionalProperties: false PoiDetalleDto: type: object properties: From fae2025b1f7ec054460c171ea646c5f3cf69cbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 18 Nov 2026 16:39:53 -0500 Subject: [PATCH 8/8] API: declarar las respuestas nuevas para que el contrato salga del Swagger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openapi.yaml se genera desde el Swagger y no se edita a mano. Las respuestas 204/404/409 del DELETE de escenas y el 404 del GET de administracion solo estaban escritas a mano en el contrato: al regenerarlo, el Swagger decia «200 OK» y se perdian. - [ProducesResponseType] en los dos endpoints. El GET declara tambien su 200: con un tipo explicito Swashbuckle deja de deducirlo. - El cuerpo del 409 pasa de un objeto anonimo a ConflictoDto (mismo JSON: mensaje y codigo), para que el contrato lo describa. - El 404 se declara como texto, que es lo que devuelve NotFound(string). - openapi.yaml regenerado con node scripts/generar_openapi.mjs; pasa el lint de redocly. --- packages/contracts/openapi.yaml | 123 +++++++++++------- .../api/Controllers/AdminEscenasController.cs | 13 +- .../api/Controllers/AdminPoisController.cs | 3 + services/api/DTOs/ConflictoDto.cs | 7 + 4 files changed, 93 insertions(+), 53 deletions(-) create mode 100644 services/api/DTOs/ConflictoDto.cs diff --git a/packages/contracts/openapi.yaml b/packages/contracts/openapi.yaml index 20b1f0b..684c649 100644 --- a/packages/contracts/openapi.yaml +++ b/packages/contracts/openapi.yaml @@ -72,10 +72,6 @@ paths: delete: tags: - AdminEscenas - summary: Elimina una escena - description: | - Si la escena es destino de hotspots de otras escenas, responde 409 - en lugar de fallar con 500 por la restricción FK. parameters: - name: id in: path @@ -85,21 +81,31 @@ paths: format: int32 responses: '204': - description: Escena eliminada + description: No Content '404': - description: La escena no existe + description: Not Found + content: + text/plain: + schema: + type: string + application/json: + schema: + type: string + text/json: + schema: + type: string '409': - description: Escena enlazada como destino desde otros hotspots + description: Conflict content: + text/plain: + schema: + $ref: '#/components/schemas/ConflictoDto' application/json: schema: - type: object - properties: - mensaje: - type: string - codigo: - type: string - example: escena_en_uso + $ref: '#/components/schemas/ConflictoDto' + text/json: + schema: + $ref: '#/components/schemas/ConflictoDto' '/api/admin/escenas/{id}/imagen': post: tags: @@ -611,42 +617,10 @@ paths: text/json: schema: $ref: '#/components/schemas/PerfilDto' - /api/admin/pois: - post: - tags: - - AdminPois - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CrearPoiRequest' - text/json: - schema: - $ref: '#/components/schemas/CrearPoiRequest' - application/*+json: - schema: - $ref: '#/components/schemas/CrearPoiRequest' - responses: - '200': - description: OK - content: - text/plain: - schema: - $ref: '#/components/schemas/PoiDto' - application/json: - schema: - $ref: '#/components/schemas/PoiDto' - text/json: - schema: - $ref: '#/components/schemas/PoiDto' '/api/admin/pois/{id}': get: tags: - AdminPois - summary: Detalle de un POI (activo o inactivo) con medios y escenas - description: | - A diferencia de GET /api/pois/{poiId}, este endpoint no filtra por - activo ni por audiencia e incluye las escenas del POI. parameters: - name: id in: path @@ -658,11 +632,27 @@ paths: '200': description: OK content: + text/plain: + schema: + $ref: '#/components/schemas/PoiDetalleAdminDto' application/json: schema: $ref: '#/components/schemas/PoiDetalleAdminDto' + text/json: + schema: + $ref: '#/components/schemas/PoiDetalleAdminDto' '404': - description: El punto de interés no existe + description: Not Found + content: + text/plain: + schema: + type: string + application/json: + schema: + type: string + text/json: + schema: + type: string put: tags: - AdminPois @@ -710,6 +700,34 @@ paths: responses: '200': description: OK + /api/admin/pois: + post: + tags: + - AdminPois + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CrearPoiRequest' + text/json: + schema: + $ref: '#/components/schemas/CrearPoiRequest' + application/*+json: + schema: + $ref: '#/components/schemas/CrearPoiRequest' + responses: + '200': + description: OK + content: + text/plain: + schema: + $ref: '#/components/schemas/PoiDto' + application/json: + schema: + $ref: '#/components/schemas/PoiDto' + text/json: + schema: + $ref: '#/components/schemas/PoiDto' /api/admin/rutas: post: tags: @@ -1159,6 +1177,16 @@ components: type: string nullable: true additionalProperties: false + ConflictoDto: + type: object + properties: + mensaje: + type: string + nullable: true + codigo: + type: string + nullable: true + additionalProperties: false ConteoTipoDto: type: object properties: @@ -1695,7 +1723,6 @@ components: additionalProperties: false PoiDetalleAdminDto: type: object - description: Detalle de POI para el panel (incluye inactivos, medios y escenas). properties: poi: $ref: '#/components/schemas/PoiDto' diff --git a/services/api/Controllers/AdminEscenasController.cs b/services/api/Controllers/AdminEscenasController.cs index c52d789..0a68548 100644 --- a/services/api/Controllers/AdminEscenasController.cs +++ b/services/api/Controllers/AdminEscenasController.cs @@ -29,7 +29,12 @@ public async Task> ActualizarEscena(int id, [FromBody] A return Ok(escena); } + // Las respuestas se declaran para que el Swagger, y con él + // packages/contracts/openapi.yaml, las documente: sin esto dice «200 OK». [HttpDelete("{id:int}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status409Conflict)] public async Task EliminarEscena(int id) { var resultado = await contenidoService.EliminarEscenaAsync(id); @@ -39,11 +44,9 @@ public async Task EliminarEscena(int id) EliminarEscenaResultado.NoExiste => NotFound("La escena no existe."), EliminarEscenaResultado.EnUsoComoDestino => - Conflict(new - { - mensaje = "No se puede eliminar la escena porque está enlazada como destino desde otra(s) escena(s). Elimina o reasigna esos hotspots primero.", - codigo = "escena_en_uso" - }), + Conflict(new ConflictoDto( + "No se puede eliminar la escena porque está enlazada como destino desde otra(s) escena(s). Elimina o reasigna esos hotspots primero.", + "escena_en_uso")), _ => NoContent() }; } diff --git a/services/api/Controllers/AdminPoisController.cs b/services/api/Controllers/AdminPoisController.cs index cbd01f1..8a644e0 100644 --- a/services/api/Controllers/AdminPoisController.cs +++ b/services/api/Controllers/AdminPoisController.cs @@ -12,7 +12,10 @@ public class AdminPoisController(IContenidoService contenidoService) : Controlle /// /// Detalle de un POI (activo o inactivo) con medios y escenas. /// + // Declarar el 404 hace que Swagger deje de deducir el 200: van los dos. [HttpGet("{id:int}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> ObtenerPoiAdmin(int id) { var detalle = await contenidoService.ObtenerPoiAdminPorIdAsync(id); diff --git a/services/api/DTOs/ConflictoDto.cs b/services/api/DTOs/ConflictoDto.cs new file mode 100644 index 0000000..d49aa80 --- /dev/null +++ b/services/api/DTOs/ConflictoDto.cs @@ -0,0 +1,7 @@ +namespace TourVirtualUTB.Api.DTOs; + +/// +/// Cuerpo de un 409: por qué no se pudo hacer el cambio y un código estable +/// para que el panel lo reconozca sin leer el mensaje. +/// +public sealed record ConflictoDto(string Mensaje, string Codigo);