diff --git a/ManagerService/Controllers/ApplicationInstanceController.cs b/ManagerService/Controllers/ApplicationInstanceController.cs index caf825e..ca652bf 100644 --- a/ManagerService/Controllers/ApplicationInstanceController.cs +++ b/ManagerService/Controllers/ApplicationInstanceController.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Manager.Helpers; using Manager.Services; using ManagerService.Data; using ManagerService.DTOs; @@ -244,6 +243,7 @@ namespace ManagerService.Controllers // Todo add some verification ? AppConfigurationLink appConfigurationLink = new AppConfigurationLink().FromDTO(appConfigurationLinkDTO); appConfigurationLink.Id = idService.GenerateHexId(); + appConfigurationLink.Order = _myInfoMateDbContext.AppConfigurationLinks.Count(acl => acl.ApplicationInstanceId == applicationInstanceId); _myInfoMateDbContext.AppConfigurationLinks.Add(appConfigurationLink); _myInfoMateDbContext.SaveChanges(); @@ -304,6 +304,49 @@ namespace ManagerService.Controllers } } + /// + /// Update app configuration links order + /// + /// App configuration link to update + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpPut("application-link/order")] + public ObjectResult UpdateApplicationLinkOrder([FromBody] List appConfigurationLinkDTOs) + { + try + { + if (appConfigurationLinkDTOs == null) + throw new ArgumentNullException("appConfigurationLink param is null"); + + List appConfigurationLinks = _myInfoMateDbContext.AppConfigurationLinks.Include(acl => acl.Configuration).Include(acl => acl.Device).Where(acl => appConfigurationLinkDTOs.Select(acld => acld.id).Contains(acl.Id)).ToList(); + + if (appConfigurationLinks.Count != appConfigurationLinkDTOs.Count) + throw new KeyNotFoundException("Length does not match"); + + foreach (var appConfigurationLinkDTO in appConfigurationLinkDTOs) { + var appConf = appConfigurationLinks.FirstOrDefault(acl => acl.Id == appConfigurationLinkDTO.id); + appConf.Order = appConfigurationLinkDTO.order; + } + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(appConfigurationLinks.Select(acl => acl.ToDTO())); + } + catch (ArgumentNullException ex) + { + return new BadRequestObjectResult(ex.Message) { }; + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + /// /// Remove configuration from instance /// diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index 57da42a..f8cf49a 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -94,6 +94,40 @@ namespace ManagerService.Controllers } } + /// + /// Get a list of all section (summary) + /// + /// id instance + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 500)] + [ProducesResponseType(typeof(string), 400)] + [HttpGet("detail")] + public ObjectResult GetAllFromType([FromQuery] string instanceId, [FromQuery] SectionType sectionType) + { + try + { + if (instanceId == null) + throw new ArgumentNullException("Param is null"); + + List
sections = _myInfoMateDbContext.Sections.Where(s => s.InstanceId == instanceId && s.Type == sectionType).OrderBy(s => s.Order).ToList(); + //List sections = _sectionService.GetAllSubSection(id); + + List sectionsToReturn = new List(); + + foreach (var section in sections) + { + var dto = SectionFactory.ToDTO(section); + sectionsToReturn.Add(dto); + } + + return new OkObjectResult(sectionsToReturn); + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + /// /// Get a list of all section from a specific configuration /// diff --git a/ManagerService/DTOs/ApplicationInstanceDTO.cs b/ManagerService/DTOs/ApplicationInstanceDTO.cs index 56cda73..99b022c 100644 --- a/ManagerService/DTOs/ApplicationInstanceDTO.cs +++ b/ManagerService/DTOs/ApplicationInstanceDTO.cs @@ -1,4 +1,5 @@ -using ManagerService.Data; +using Manager.DTOs; +using ManagerService.Data; using System.Collections.Generic; namespace ManagerService.DTOs @@ -25,6 +26,12 @@ namespace ManagerService.DTOs public string secondaryColor { get; set; } - public List languages { get; set; } + public LayoutMainPageType layoutMainPage { get; set; } + + public List languages { get; set; } + + public string sectionEventId { get; set; } + + public SectionEventDTO? sectionEventDTO { get; set; } } } diff --git a/ManagerService/Data/ApplicationInstance.cs b/ManagerService/Data/ApplicationInstance.cs index 102d469..a8dab72 100644 --- a/ManagerService/Data/ApplicationInstance.cs +++ b/ManagerService/Data/ApplicationInstance.cs @@ -1,5 +1,7 @@ -using ManagerService.Data.SubSection; +using Manager.DTOs; +using ManagerService.Data.SubSection; using ManagerService.DTOs; +using ManagerService.Services; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -59,7 +61,10 @@ namespace ManagerService.Data loaderImageUrl = LoaderImageUrl, primaryColor = PrimaryColor, secondaryColor = SecondaryColor, - languages = Languages + layoutMainPage = LayoutMainPage, + languages = Languages, + sectionEventId = SectionEventId, + sectionEventDTO = SectionEvent != null ? SectionFactory.ToDTO(SectionEvent) as SectionEventDTO : null }; } @@ -73,8 +78,10 @@ namespace ManagerService.Data LoaderImageUrl = dto.loaderImageUrl; PrimaryColor = dto.primaryColor; SecondaryColor = dto.secondaryColor; + LayoutMainPage = dto.layoutMainPage; Languages = dto.languages; Configurations = dto.configurations; + SectionEventId = dto.sectionEventId; return this; } diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index 0b4a75d..4d4fc8c 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -188,7 +188,7 @@ namespace ManagerService app.UseCors( #if DEBUG options => options - .SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:64515") + .SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:59952") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()