misc + fixs
This commit is contained in:
parent
5aabf35f9d
commit
c8c5902292
@ -17,7 +17,7 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
[Authorize] // TODO Add ROLES (Roles = "Admin")
|
[Authorize] // TODO Add ROLES (Roles = "Admin")
|
||||||
[ApiController, Route("api/[controller]")]
|
[ApiController, Route("api/[controller]")]
|
||||||
[OpenApiTag("Instance", Description = "Application instance management")]
|
[OpenApiTag("ApplicationInstance", Description = "Application instance management")]
|
||||||
public class ApplicationInstanceController : ControllerBase
|
public class ApplicationInstanceController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
||||||
@ -190,13 +190,12 @@ namespace ManagerService.Controllers
|
|||||||
[ProducesResponseType(typeof(List<AppConfigurationLinkDTO>), 200)]
|
[ProducesResponseType(typeof(List<AppConfigurationLinkDTO>), 200)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
[HttpGet("{applicationInstanceId}/application-link")]
|
[HttpGet("{applicationInstanceId}/application-link")]
|
||||||
public ObjectResult GetAllApplicationLinkFromApplicationInstance([FromQuery] string applicationInstanceId)
|
public ObjectResult GetAllApplicationLinkFromApplicationInstance(string applicationInstanceId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<AppConfigurationLink> appConfigurationLinks = _myInfoMateDbContext.AppConfigurationLinks.Where(acl => acl.ApplicationInstanceId == applicationInstanceId).ToList();
|
List<AppConfigurationLink> appConfigurationLinks = _myInfoMateDbContext.AppConfigurationLinks.Include(acl => acl.Configuration).Where(acl => acl.ApplicationInstanceId == applicationInstanceId).ToList();
|
||||||
|
return new OkObjectResult(appConfigurationLinks.Select(acl => acl.ToDTO()).OrderBy(acl => acl.order).ToList());
|
||||||
return new OkObjectResult(appConfigurationLinks.Select(acl => acl.ToDTO()).OrderBy(acl => acl.order));
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -234,6 +233,10 @@ namespace ManagerService.Controllers
|
|||||||
if (configuration == null)
|
if (configuration == null)
|
||||||
throw new KeyNotFoundException("This configuration was not found");
|
throw new KeyNotFoundException("This configuration was not found");
|
||||||
|
|
||||||
|
// Check if already linked
|
||||||
|
if (_myInfoMateDbContext.AppConfigurationLinks.Any(acl => acl.ConfigurationId == appConfigurationLinkDTO.configurationId && acl.ApplicationInstanceId == applicationInstanceId))
|
||||||
|
return new ConflictObjectResult("This configuration is already linked to this applicationInstance");
|
||||||
|
|
||||||
// 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();
|
||||||
|
|||||||
@ -76,7 +76,9 @@ namespace ManagerService.Controllers
|
|||||||
if (instance == null)
|
if (instance == null)
|
||||||
throw new KeyNotFoundException("This instance was not found");
|
throw new KeyNotFoundException("This instance was not found");
|
||||||
|
|
||||||
return new OkObjectResult(instance.ToDTO());
|
var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.InstanceId == instance.Id).ToList();
|
||||||
|
|
||||||
|
return new OkObjectResult(instance.ToDTO(applicationInstances.Select(ai => ai.ToDTO()).ToList()));
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException ex)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
@ -121,7 +123,9 @@ namespace ManagerService.Controllers
|
|||||||
_myInfoMateDbContext.Instances.Add(instance);
|
_myInfoMateDbContext.Instances.Add(instance);
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
return new OkObjectResult(instance.ToDTO());
|
var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.InstanceId == instance.Id).ToList();
|
||||||
|
|
||||||
|
return new OkObjectResult(instance.ToDTO(applicationInstances.Select(ai => ai.ToDTO()).ToList()));
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
@ -167,7 +171,9 @@ namespace ManagerService.Controllers
|
|||||||
//OldInstance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
//OldInstance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
return new OkObjectResult(instance.ToDTO());
|
var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.InstanceId == instance.Id).ToList();
|
||||||
|
|
||||||
|
return new OkObjectResult(instance.ToDTO(applicationInstances.Select(ai => ai.ToDTO()).ToList()));
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
@ -202,7 +208,9 @@ namespace ManagerService.Controllers
|
|||||||
if (instance == null)
|
if (instance == null)
|
||||||
throw new KeyNotFoundException("Instance was not found");
|
throw new KeyNotFoundException("Instance was not found");
|
||||||
|
|
||||||
return new OkObjectResult(instance.ToDTO());
|
var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.InstanceId == instance.Id).ToList();
|
||||||
|
|
||||||
|
return new OkObjectResult(instance.ToDTO(applicationInstances.Select(ai => ai.ToDTO()).ToList()));
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException ex)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
public string configurationId { get; set; }
|
public string configurationId { get; set; }
|
||||||
|
|
||||||
|
public ConfigurationDTO configuration { get; set; }
|
||||||
|
|
||||||
public string applicationInstanceId { get; set; }
|
public string applicationInstanceId { get; set; }
|
||||||
|
|
||||||
public int? order { get; set; }
|
public int? order { get; set; }
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ManagerService.DTOs
|
namespace ManagerService.DTOs
|
||||||
{
|
{
|
||||||
@ -14,5 +15,7 @@ namespace ManagerService.DTOs
|
|||||||
public bool isTablet { get; set; }
|
public bool isTablet { get; set; }
|
||||||
public bool isWeb { get; set; }
|
public bool isWeb { get; set; }
|
||||||
public bool isVR { get; set; }
|
public bool isVR { get; set; }
|
||||||
|
|
||||||
|
public List<ApplicationInstanceDTO> applicationInstanceDTOs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ namespace ManagerService.Data
|
|||||||
{
|
{
|
||||||
id = Id,
|
id = Id,
|
||||||
configurationId = ConfigurationId,
|
configurationId = ConfigurationId,
|
||||||
|
configuration = Configuration?.ToDTO(new List<String>()),
|
||||||
applicationInstanceId = ApplicationInstanceId,
|
applicationInstanceId = ApplicationInstanceId,
|
||||||
order = Order,
|
order = Order,
|
||||||
isActive = IsActive,
|
isActive = IsActive,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using ManagerService.DTOs;
|
using ManagerService.DTOs;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace ManagerService.Data
|
namespace ManagerService.Data
|
||||||
@ -33,7 +34,7 @@ namespace ManagerService.Data
|
|||||||
public bool IsVR { get; set; }
|
public bool IsVR { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public InstanceDTO ToDTO()
|
public InstanceDTO ToDTO(List<ApplicationInstanceDTO> applicationInstanceDTOs)
|
||||||
{
|
{
|
||||||
return new InstanceDTO()
|
return new InstanceDTO()
|
||||||
{
|
{
|
||||||
@ -47,6 +48,7 @@ namespace ManagerService.Data
|
|||||||
isTablet = IsTablet,
|
isTablet = IsTablet,
|
||||||
isWeb = IsWeb,
|
isWeb = IsWeb,
|
||||||
isVR = IsVR,
|
isVR = IsVR,
|
||||||
|
applicationInstanceDTOs = applicationInstanceDTOs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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:53264")
|
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:62150")
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials()
|
.AllowCredentials()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user