Skip to content
123 changes: 104 additions & 19 deletions packages/contracts/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,32 @@ paths:
type: integer
format: int32
responses:
'200':
description: OK
'204':
description: No Content
'404':
description: Not Found
content:
text/plain:
schema:
type: string
application/json:
schema:
type: string
text/json:
schema:
type: string
'409':
description: Conflict
content:
text/plain:
schema:
$ref: '#/components/schemas/ConflictoDto'
application/json:
schema:
$ref: '#/components/schemas/ConflictoDto'
text/json:
schema:
$ref: '#/components/schemas/ConflictoDto'
'/api/admin/escenas/{id}/imagen':
post:
tags:
Expand Down Expand Up @@ -593,35 +617,42 @@ paths:
text/json:
schema:
$ref: '#/components/schemas/PerfilDto'
/api/admin/pois:
post:
'/api/admin/pois/{id}':
get:
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'
parameters:
- name: id
in: path
required: true
schema:
type: integer
format: int32
responses:
'200':
description: OK
content:
text/plain:
schema:
$ref: '#/components/schemas/PoiDto'
$ref: '#/components/schemas/PoiDetalleAdminDto'
application/json:
schema:
$ref: '#/components/schemas/PoiDto'
$ref: '#/components/schemas/PoiDetalleAdminDto'
text/json:
schema:
$ref: '#/components/schemas/PoiDto'
'/api/admin/pois/{id}':
$ref: '#/components/schemas/PoiDetalleAdminDto'
'404':
description: Not Found
content:
text/plain:
schema:
type: string
application/json:
schema:
type: string
text/json:
schema:
type: string
put:
tags:
- AdminPois
Expand Down Expand Up @@ -669,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:
Expand Down Expand Up @@ -1118,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:
Expand Down Expand Up @@ -1652,6 +1721,22 @@ components:
$ref: '#/components/schemas/Medio'
nullable: true
additionalProperties: false
PoiDetalleAdminDto:
type: object
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:
Expand Down
19 changes: 16 additions & 3 deletions services/api/Controllers/AdminEscenasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@ public async Task<ActionResult<EscenaDto>> 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<string>(StatusCodes.Status404NotFound)]
[ProducesResponseType<ConflictoDto>(StatusCodes.Status409Conflict)]
public async Task<IActionResult> 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 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()
};
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions services/api/Controllers/AdminPoisController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ namespace TourVirtualUTB.Api.Controllers;
[RequiereClaveAdmin]
public class AdminPoisController(IContenidoService contenidoService) : ControllerBase
{
/// <summary>
/// Detalle de un POI (activo o inactivo) con medios y escenas.
/// </summary>
// Declarar el 404 hace que Swagger deje de deducir el 200: van los dos.
[HttpGet("{id:int}")]
[ProducesResponseType<PoiDetalleAdminDto>(StatusCodes.Status200OK)]
[ProducesResponseType<string>(StatusCodes.Status404NotFound)]
public async Task<ActionResult<PoiDetalleAdminDto>> 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<ActionResult<PoiDto>> CrearPoi([FromBody] CrearPoiRequest request)
{
Expand Down
7 changes: 7 additions & 0 deletions services/api/DTOs/ConflictoDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TourVirtualUTB.Api.DTOs;

/// <summary>
/// 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.
/// </summary>
public sealed record ConflictoDto(string Mensaje, string Codigo);
10 changes: 10 additions & 0 deletions services/api/DTOs/PoiDetalleAdminDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TourVirtualUTB.Api.DTOs;

/// <summary>
/// Detalle de un POI para el panel de administración: incluye inactivos,
/// medios y escenas asociadas.
/// </summary>
public sealed record PoiDetalleAdminDto(
PoiDto poi,
IReadOnlyList<MedioDto> medios,
IReadOnlyList<EscenaDto> escenas);
55 changes: 52 additions & 3 deletions services/api/Services/ContenidoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,50 @@ public async Task<IReadOnlyList<PoiDto>> ObtenerPoisAsync(int lugarId, Audiencia
return new PoiDetalleDto(Dto.Poi(poi), medios.Select(Dto.Medio).ToList());
}

/// <summary>
/// Detalle para el panel: funciona con POIs activos e inactivos y
/// incluye las escenas del POI (además de los medios).
/// </summary>
public async Task<PoiDetalleAdminDto?> 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.
Expand Down Expand Up @@ -221,14 +265,19 @@ public async Task<EscenaDto> CrearEscenaAsync(CrearEscenaRequest request)
return Dto.Escena(escena);
}

public async Task<bool> EliminarEscenaAsync(int id)
public async Task<EliminarEscenaResultado> 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) ---
Expand Down
13 changes: 13 additions & 0 deletions services/api/Services/EliminarEscenaResultado.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TourVirtualUTB.Api.Services;

/// <summary>Resultado de intentar borrar una escena.</summary>
public enum EliminarEscenaResultado
{
Eliminada,
NoExiste,
/// <summary>
/// Hay hotspots de otras escenas que apuntan a esta como destino
/// (FK Restrict en EscenaDestinoId).
/// </summary>
EnUsoComoDestino
}
4 changes: 3 additions & 1 deletion services/api/Services/IContenidoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface IContenidoService
Task<IReadOnlyList<PoiDto>> ObtenerPoisAsync(int lugarId, Audiencia audiencia);
Task<RecorridoDto?> ObtenerRecorridoAsync(int lugarId, Audiencia audiencia);
Task<PoiDetalleDto?> ObtenerPoiPorIdAsync(int poiId, Audiencia audiencia);
/// <summary>Detalle admin: POI activo o inactivo, con medios y escenas.</summary>
Task<PoiDetalleAdminDto?> ObtenerPoiAdminPorIdAsync(int poiId);
Task<RutaDto?> ObtenerRutaActivaAsync(int lugarId, Audiencia audiencia);
Task<string?> ObtenerRutaMapaLugarAsync(int lugarId);
Task<bool> ActualizarMapaLugarAsync(int lugarId, string rutaS3);
Expand All @@ -22,7 +24,7 @@ public interface IContenidoService
// Escenas
Task<EscenaDto> CrearEscenaAsync(CrearEscenaRequest request);
Task<EscenaDto?> ActualizarEscenaAsync(int id, ActualizarEscenaRequest request);
Task<bool> EliminarEscenaAsync(int id);
Task<EliminarEscenaResultado> EliminarEscenaAsync(int id);

// Hotspots
Task<HotspotDto> CrearHotspotAsync(CrearHotspotRequest request);
Expand Down
Loading