diff --git a/Manager.Interfaces/DTO/ConfigurationDTO.cs b/Manager.Interfaces/DTO/ConfigurationDTO.cs index 7a10f23..dd015d8 100644 --- a/Manager.Interfaces/DTO/ConfigurationDTO.cs +++ b/Manager.Interfaces/DTO/ConfigurationDTO.cs @@ -21,5 +21,6 @@ namespace Manager.Interfaces.DTO /*public string latitude { get; set; } // MyVisit - latitude of visit ? (MyVisit) public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/ public string instanceId { get; set; } + public List sectionIds { get; set; } } } diff --git a/Manager.Interfaces/Models/Configuration.cs b/Manager.Interfaces/Models/Configuration.cs index 9b337d0..7a7160c 100644 --- a/Manager.Interfaces/Models/Configuration.cs +++ b/Manager.Interfaces/Models/Configuration.cs @@ -2,6 +2,7 @@ using MongoDB.Bson.Serialization.Attributes; using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace Manager.Interfaces.Models @@ -54,7 +55,7 @@ namespace Manager.Interfaces.Models [BsonRequired] public string InstanceId { get; set; } - public ConfigurationDTO ToDTO() + public ConfigurationDTO ToDTO(List sectionIds) { return new ConfigurationDTO() { @@ -71,6 +72,7 @@ namespace Manager.Interfaces.Models isTablet = IsTablet, isOffline = IsOffline, instanceId = InstanceId, + sectionIds = sectionIds }; } @@ -92,6 +94,7 @@ namespace Manager.Interfaces.Models sections = sections, resources = resources, instanceId = InstanceId, + sectionIds = sections.Select(s => s.id).ToList() }; } } diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index a761d52..0f8be05 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -56,7 +56,16 @@ namespace ManagerService.Controllers { List configurations = _configurationService.GetAll(instanceId); - return new OkObjectResult(configurations.Select(r => r.ToDTO())); + List configurationDTOs = new List(); + + foreach(var configuration in configurations) + { + List sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id); + ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds); + configurationDTOs.Add(configurationDTO); + } + + return new OkObjectResult(configurationDTOs); } catch (Exception ex) { @@ -83,7 +92,9 @@ namespace ManagerService.Controllers if (configuration == null) throw new KeyNotFoundException("This configuration was not found"); - return new OkObjectResult(configuration.ToDTO()); + List sectionIds = _sectionService.GetAllIdsFromConfiguration(id); + + return new OkObjectResult(configuration.ToDTO(sectionIds)); } catch (KeyNotFoundException ex) { @@ -133,7 +144,7 @@ namespace ManagerService.Controllers Configuration configurationCreated = _configurationService.Create(configuration); - return new OkObjectResult(configurationCreated.ToDTO()); + return new OkObjectResult(configurationCreated.ToDTO(new List())); // Empty list } catch (ArgumentNullException ex) { @@ -187,8 +198,10 @@ namespace ManagerService.Controllers Configuration configurationModified = _configurationService.Update(updatedConfiguration.id, configuration); // TODO HANDLE MqttClientService.PublishMessage($"config/{configurationModified.Id}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true })); + + List sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id); - return new OkObjectResult(configurationModified.ToDTO()); + return new OkObjectResult(configurationModified.ToDTO(sectionIds)); } catch (ArgumentNullException ex) { diff --git a/ManagerService/Services/SectionDatabaseService.cs b/ManagerService/Services/SectionDatabaseService.cs index 6024f00..1007ead 100644 --- a/ManagerService/Services/SectionDatabaseService.cs +++ b/ManagerService/Services/SectionDatabaseService.cs @@ -29,6 +29,11 @@ namespace Manager.Services return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList(); } + public List GetAllIdsFromConfiguration(string configurationId) + { + return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList().Select(s => s.Id).ToList(); + } + public List
GetAllSubSection(string parentId) { return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();