Added method to return all section from one type + misc

This commit is contained in:
Thomas Fransolet 2025-09-18 23:23:36 +02:00
parent fd191ec647
commit 8f16f1570f
5 changed files with 97 additions and 6 deletions

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Manager.Helpers;
using Manager.Services; using Manager.Services;
using ManagerService.Data; using ManagerService.Data;
using ManagerService.DTOs; using ManagerService.DTOs;
@ -244,6 +243,7 @@ namespace ManagerService.Controllers
// Todo add some verification ? // Todo add some verification ?
AppConfigurationLink appConfigurationLink = new AppConfigurationLink().FromDTO(appConfigurationLinkDTO); AppConfigurationLink appConfigurationLink = new AppConfigurationLink().FromDTO(appConfigurationLinkDTO);
appConfigurationLink.Id = idService.GenerateHexId(); appConfigurationLink.Id = idService.GenerateHexId();
appConfigurationLink.Order = _myInfoMateDbContext.AppConfigurationLinks.Count(acl => acl.ApplicationInstanceId == applicationInstanceId);
_myInfoMateDbContext.AppConfigurationLinks.Add(appConfigurationLink); _myInfoMateDbContext.AppConfigurationLinks.Add(appConfigurationLink);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
@ -304,6 +304,49 @@ namespace ManagerService.Controllers
} }
} }
/// <summary>
/// Update app configuration links order
/// </summary>
/// <param name="appConfigurationLinkDTO">App configuration link to update</param>
[ProducesResponseType(typeof(List<AppConfigurationLinkDTO>), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpPut("application-link/order")]
public ObjectResult UpdateApplicationLinkOrder([FromBody] List<AppConfigurationLinkDTO> appConfigurationLinkDTOs)
{
try
{
if (appConfigurationLinkDTOs == null)
throw new ArgumentNullException("appConfigurationLink param is null");
List<AppConfigurationLink> 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 };
}
}
/// <summary> /// <summary>
/// Remove configuration from instance /// Remove configuration from instance
/// </summary> /// </summary>

View File

@ -94,6 +94,40 @@ namespace ManagerService.Controllers
} }
} }
/// <summary>
/// Get a list of all section (summary)
/// </summary>
/// <param name="id">id instance</param>
[ProducesResponseType(typeof(List<SectionDTO>), 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<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.InstanceId == instanceId && s.Type == sectionType).OrderBy(s => s.Order).ToList();
//List<OldSection> sections = _sectionService.GetAllSubSection(id);
List<object> sectionsToReturn = new List<object>();
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 };
}
}
/// <summary> /// <summary>
/// Get a list of all section from a specific configuration /// Get a list of all section from a specific configuration
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using ManagerService.Data; using Manager.DTOs;
using ManagerService.Data;
using System.Collections.Generic; using System.Collections.Generic;
namespace ManagerService.DTOs namespace ManagerService.DTOs
@ -25,6 +26,12 @@ namespace ManagerService.DTOs
public string secondaryColor { get; set; } public string secondaryColor { get; set; }
public LayoutMainPageType layoutMainPage { get; set; }
public List<string> languages { get; set; } public List<string> languages { get; set; }
public string sectionEventId { get; set; }
public SectionEventDTO? sectionEventDTO { get; set; }
} }
} }

View File

@ -1,5 +1,7 @@
using ManagerService.Data.SubSection; using Manager.DTOs;
using ManagerService.Data.SubSection;
using ManagerService.DTOs; using ManagerService.DTOs;
using ManagerService.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@ -59,7 +61,10 @@ namespace ManagerService.Data
loaderImageUrl = LoaderImageUrl, loaderImageUrl = LoaderImageUrl,
primaryColor = PrimaryColor, primaryColor = PrimaryColor,
secondaryColor = SecondaryColor, 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; LoaderImageUrl = dto.loaderImageUrl;
PrimaryColor = dto.primaryColor; PrimaryColor = dto.primaryColor;
SecondaryColor = dto.secondaryColor; SecondaryColor = dto.secondaryColor;
LayoutMainPage = dto.layoutMainPage;
Languages = dto.languages; Languages = dto.languages;
Configurations = dto.configurations; Configurations = dto.configurations;
SectionEventId = dto.sectionEventId;
return this; return this;
} }

View File

@ -188,7 +188,7 @@ namespace ManagerService
app.UseCors( app.UseCors(
#if DEBUG #if DEBUG
options => options options => options
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:64515") .SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:59952")
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.AllowCredentials() .AllowCredentials()