Add get beacons method

This commit is contained in:
Fransolet Thomas 2023-01-28 01:23:35 +01:00
parent 006aa541cd
commit 52ec413761

View File

@ -230,6 +230,38 @@ namespace ManagerService.Controllers
}
}
/// <summary>
/// Get all section with beacon
/// </summary>
/// <param name="id">Instance id</param>
[AllowAnonymous]
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpGet("beacons/{id}")]
public ObjectResult GetAllBeaconsForInstance(string id)
{
try
{
List<Section> sections = _sectionService.GetAll(id);
if (sections.Count == 0)
throw new KeyNotFoundException("No section has beacon");
sections = sections.Where(s => s.IsBeacon && s.BeaconId != null).ToList();
return new OkObjectResult(sections.Select(s => s.ToDTO()));
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Create a new section
/// </summary>