diff --git a/Manager.Interfaces/DTO/ConfigurationDTO.cs b/Manager.Interfaces/DTO/ConfigurationDTO.cs index dd015d8..4c8a6e3 100644 --- a/Manager.Interfaces/DTO/ConfigurationDTO.cs +++ b/Manager.Interfaces/DTO/ConfigurationDTO.cs @@ -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 sectionIds { get; set; } + public int pinCode { get; set; } // 4 number } } diff --git a/Manager.Interfaces/DTO/InstanceDTO.cs b/Manager.Interfaces/DTO/InstanceDTO.cs index 5e371a5..f600012 100644 --- a/Manager.Interfaces/DTO/InstanceDTO.cs +++ b/Manager.Interfaces/DTO/InstanceDTO.cs @@ -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; } } } diff --git a/Manager.Interfaces/Models/Configuration.cs b/Manager.Interfaces/Models/Configuration.cs index 7a7160c..3e9b943 100644 --- a/Manager.Interfaces/Models/Configuration.cs +++ b/Manager.Interfaces/Models/Configuration.cs @@ -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 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() }; } diff --git a/Manager.Interfaces/Models/Instance.cs b/Manager.Interfaces/Models/Instance.cs index bcc0cf5..6d541c8 100644 --- a/Manager.Interfaces/Models/Instance.cs +++ b/Manager.Interfaces/Models/Instance.cs @@ -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 }; } diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index fc6d49a..a268bb9 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -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 _logger; private readonly IConfiguration _configuration; - public ConfigurationController(IConfiguration configuration, ILogger logger, ConfigurationDatabaseService configurationService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, ResourceDataDatabaseService resourceDataService, DeviceDatabaseService deviceService) + public ConfigurationController(IConfiguration configuration, ILogger 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 } } + /// + /// Get Confuguration list by instanceId' pincode + /// + /// Code pin + [AllowAnonymous] + [ProducesResponseType(typeof(List), 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 configurations = _configurationService.GetAll(instance.Id); + List configurationDTOs = new List(); + foreach (var configuration in configurations) + { + List sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id); + configurationDTOs.Add(configuration.ToDTO(sectionIds)); + } + + return new OkObjectResult(configurationDTOs); + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } /// /// Get a specific display configuration diff --git a/ManagerService/Controllers/InstanceController.cs b/ManagerService/Controllers/InstanceController.cs index f461422..6b5fd4e 100644 --- a/ManagerService/Controllers/InstanceController.cs +++ b/ManagerService/Controllers/InstanceController.cs @@ -164,6 +164,32 @@ namespace ManagerService.Controllers } } + /// + /// Get Instance by pincode + /// + /// Code pin + [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 }; + } + } + /// /// Delete an instance diff --git a/ManagerService/Services/InstanceDatabaseService.cs b/ManagerService/Services/InstanceDatabaseService.cs index 6b6e8c7..35ccbad 100644 --- a/ManagerService/Services/InstanceDatabaseService.cs +++ b/ManagerService/Services/InstanceDatabaseService.cs @@ -33,6 +33,11 @@ namespace Manager.Services return _Instances.Find(i => i.Id == id).FirstOrDefault(); } + public Instance GetByPinCode(int pinCode) + { + return _Instances.Find(c => c.PinCode == pinCode).FirstOrDefault(); + } + public bool IsExist(string id) { return _Instances.Find(i => i.Id == id).FirstOrDefault() != null ? true : false;