Add pinCode to instance + endpoints
This commit is contained in:
parent
19d84b4417
commit
1e31ebe094
@ -22,5 +22,6 @@ namespace Manager.Interfaces.DTO
|
||||
public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/
|
||||
public string instanceId { get; set; }
|
||||
public List<string> sectionIds { get; set; }
|
||||
public int pinCode { get; set; } // 4 number
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,5 +9,6 @@ namespace Manager.Interfaces.DTO
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public DateTime dateCreation { get; set; }
|
||||
public int? pinCode { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,9 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string InstanceId { get; set; }
|
||||
|
||||
[BsonElement("PinCode")]
|
||||
public int PinCode { get; set; }
|
||||
|
||||
public ConfigurationDTO ToDTO(List<string> sectionIds)
|
||||
{
|
||||
return new ConfigurationDTO()
|
||||
@ -72,6 +75,7 @@ namespace Manager.Interfaces.Models
|
||||
isTablet = IsTablet,
|
||||
isOffline = IsOffline,
|
||||
instanceId = InstanceId,
|
||||
pinCode = PinCode,
|
||||
sectionIds = sectionIds
|
||||
};
|
||||
}
|
||||
@ -94,6 +98,7 @@ namespace Manager.Interfaces.Models
|
||||
sections = sections,
|
||||
resources = resources,
|
||||
instanceId = InstanceId,
|
||||
pinCode = PinCode,
|
||||
sectionIds = sections.Select(s => s.id).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
@ -22,13 +22,17 @@ namespace Manager.Interfaces.Models
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
[BsonElement("PinCode")]
|
||||
public int? PinCode { get; set; }
|
||||
|
||||
public InstanceDTO ToDTO()
|
||||
{
|
||||
return new InstanceDTO()
|
||||
{
|
||||
id = Id,
|
||||
name = Name,
|
||||
dateCreation = DateCreation
|
||||
dateCreation = DateCreation,
|
||||
pinCode = PinCode
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ namespace ManagerService.Controllers
|
||||
public class ConfigurationController : ControllerBase
|
||||
{
|
||||
private ConfigurationDatabaseService _configurationService;
|
||||
private InstanceDatabaseService _instanceService;
|
||||
private SectionDatabaseService _sectionService;
|
||||
private ResourceDatabaseService _resourceService;
|
||||
private ResourceDataDatabaseService _resourceDataService;
|
||||
@ -31,11 +32,12 @@ namespace ManagerService.Controllers
|
||||
private readonly ILogger<ConfigurationController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, ResourceDataDatabaseService resourceDataService, DeviceDatabaseService deviceService)
|
||||
public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, InstanceDatabaseService instanceService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, ResourceDataDatabaseService resourceDataService, DeviceDatabaseService deviceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_configurationService = configurationService;
|
||||
_instanceService = instanceService;
|
||||
_sectionService = sectionService;
|
||||
_resourceService = resourceService;
|
||||
_resourceDataService = resourceDataService;
|
||||
@ -73,6 +75,39 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Confuguration list by instanceId' pincode
|
||||
/// </summary>
|
||||
/// <param name="pinCode">Code pin</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(List<ConfigurationDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("byPin")]
|
||||
public ObjectResult GetConfigurationsByPinCode([FromQuery] int pinCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
Instance instance = _instanceService.GetByPinCode(pinCode);
|
||||
|
||||
if (instance == null)
|
||||
throw new KeyNotFoundException("None instance is linked to this pin code");
|
||||
|
||||
List<Configuration> configurations = _configurationService.GetAll(instance.Id);
|
||||
List<ConfigurationDTO> configurationDTOs = new List<ConfigurationDTO>();
|
||||
foreach (var configuration in configurations)
|
||||
{
|
||||
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id);
|
||||
configurationDTOs.Add(configuration.ToDTO(sectionIds));
|
||||
}
|
||||
|
||||
return new OkObjectResult(configurationDTOs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific display configuration
|
||||
|
||||
@ -164,6 +164,32 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Instance by pincode
|
||||
/// </summary>
|
||||
/// <param name="pinCode">Code pin</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(InstanceDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("byPin")]
|
||||
public ObjectResult GetInstanceByPinCode([FromQuery] int pinCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
Instance instance = _instanceService.GetByPinCode(pinCode);
|
||||
|
||||
if (instance == null)
|
||||
throw new KeyNotFoundException("Instance was not found");
|
||||
|
||||
return new OkObjectResult(instance.ToDTO());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete an instance
|
||||
|
||||
@ -33,6 +33,11 @@ namespace Manager.Services
|
||||
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Instance GetByPinCode(int pinCode)
|
||||
{
|
||||
return _Instances.Find<Instance>(c => c.PinCode == pinCode).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Instances.Find<Instance>(i => i.Id == id).FirstOrDefault() != null ? true : false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user