Update get ressources endpoint by adding types filter

This commit is contained in:
Fransolet Thomas 2022-10-27 13:31:38 +02:00
parent 5b56c677ef
commit 3e6439433e
2 changed files with 15 additions and 4 deletions

View File

@ -44,14 +44,25 @@ namespace ManagerService.Controllers
/// Get a list of all resources (summary)
/// </summary>
/// <param name="id">id instance</param>
/// <param name="types">types of resource</param>
[ProducesResponseType(typeof(List<ResourceDTO>), 200)]
[ProducesResponseType(typeof(string), 500)]
[HttpGet]
public ObjectResult Get([FromQuery] string instanceId)
public ObjectResult Get([FromQuery] string instanceId, [FromQuery] List<ResourceType> types)
{
try
{
List<Resource> resources = _resourceService.GetAll(instanceId);
if (instanceId == null)
throw new ArgumentNullException("InstanceId needed");
List<Resource> resources = new List<Resource>();
if (types.Count > 0)
{
resources = _resourceService.GetAllByType(instanceId, types);
}
else
{
resources = _resourceService.GetAll(instanceId);
}
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
foreach(var resource in resources)

View File

@ -23,9 +23,9 @@ namespace Manager.Services
return _Resources.Find(r => r.InstanceId == instanceId).ToList();
}
public Resource GetByType(ResourceType type)
public List<Resource> GetAllByType(string instanceId, List<ResourceType> types)
{
return _Resources.Find<Resource>(r => r.Type == type).FirstOrDefault();
return _Resources.Find<Resource>(r => r.InstanceId == instanceId && types.Contains(r.Type)).ToList();
}
public Resource GetById(string id)