Added method to return all section from one type + misc
This commit is contained in:
parent
fd191ec647
commit
8f16f1570f
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Remove configuration from instance
|
||||
/// </summary>
|
||||
|
||||
@ -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>
|
||||
/// Get a list of all section from a specific configuration
|
||||
/// </summary>
|
||||
|
||||
@ -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 LayoutMainPageType layoutMainPage { get; set; }
|
||||
|
||||
public List<string> languages { get; set; }
|
||||
|
||||
public string sectionEventId { get; set; }
|
||||
|
||||
public SectionEventDTO? sectionEventDTO { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user