Add get beacons method
This commit is contained in:
parent
006aa541cd
commit
52ec413761
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user