Add configuration label to device DTO
This commit is contained in:
parent
26253f281e
commit
22c34d90a6
@ -10,6 +10,7 @@ namespace Manager.Interfaces.DTO
|
||||
public string Name { get; set; }
|
||||
public string IpAddress { get; set; }
|
||||
public string ConfigurationId { get; set; }
|
||||
public string Configuration { get; set; }
|
||||
public bool Connected{ get; set; }
|
||||
public DateTime DateCreation{ get; set; }
|
||||
}
|
||||
|
||||
@ -22,9 +22,12 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRequired]
|
||||
public string IpAddress { get; set; }
|
||||
|
||||
[BsonElement("Configuration")]
|
||||
public string Configuration { get; set; }
|
||||
|
||||
[BsonElement("ConfigurationId")]
|
||||
[BsonRequired]
|
||||
public string ConfigurationId { get; set; }
|
||||
public string ConfigurationId { get; set; }
|
||||
|
||||
[BsonElement("Connected")]
|
||||
[BsonRequired]
|
||||
@ -56,6 +59,7 @@ namespace Manager.Interfaces.Models
|
||||
Name = Name,
|
||||
IpAddress = IpAddress,
|
||||
Connected = Connected,
|
||||
Configuration = Configuration,
|
||||
ConfigurationId = ConfigurationId,
|
||||
DateCreation = DateCreation
|
||||
};
|
||||
@ -69,6 +73,7 @@ namespace Manager.Interfaces.Models
|
||||
Name = Name,
|
||||
IpAddress = IpAddress,
|
||||
Connected = Connected,
|
||||
Configuration = Configuration,
|
||||
ConfigurationId = ConfigurationId,
|
||||
ConnectionLevel = ConnectionLevel,
|
||||
LastConnectionLevel = LastConnectionLevel,
|
||||
|
||||
@ -22,12 +22,14 @@ namespace ManagerService.Controllers
|
||||
public class DeviceController : ControllerBase
|
||||
{
|
||||
private DeviceDatabaseService _deviceService;
|
||||
private ConfigurationDatabaseService _configurationService;
|
||||
private readonly ILogger<DeviceController> _logger;
|
||||
|
||||
public DeviceController(ILogger<DeviceController> logger, DeviceDatabaseService deviceService)
|
||||
public DeviceController(ILogger<DeviceController> logger, DeviceDatabaseService deviceService, ConfigurationDatabaseService configurationService)
|
||||
{
|
||||
_logger = logger;
|
||||
_deviceService = deviceService;
|
||||
_configurationService = configurationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,6 +89,7 @@ namespace ManagerService.Controllers
|
||||
/// <param name="newDevice">New device info</param>
|
||||
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 409)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPost]
|
||||
@ -97,9 +100,14 @@ namespace ManagerService.Controllers
|
||||
if (newDevice == null)
|
||||
throw new ArgumentNullException("Device param is null");
|
||||
|
||||
// Todo add some verification ?
|
||||
var configuration = _configurationService.GetById(newDevice.ConfigurationId);
|
||||
|
||||
if (configuration == null)
|
||||
throw new KeyNotFoundException("Configuration does not exist");
|
||||
|
||||
Device device = new Device();
|
||||
device.Name = newDevice.Name;
|
||||
device.Configuration = configuration.Label;
|
||||
device.ConfigurationId = newDevice.ConfigurationId;
|
||||
device.IpAddress = newDevice.IpAddress;
|
||||
device.Connected = newDevice.Connected;
|
||||
@ -117,6 +125,10 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return new ConflictObjectResult(ex.Message) { };
|
||||
@ -197,9 +209,15 @@ namespace ManagerService.Controllers
|
||||
if (device == null)
|
||||
throw new KeyNotFoundException("Device does not exist");
|
||||
|
||||
var configuration = _configurationService.GetById(deviceIn.ConfigurationId);
|
||||
|
||||
if (configuration == null)
|
||||
throw new KeyNotFoundException("Configuration does not exist");
|
||||
|
||||
// Todo add some verification ?
|
||||
device.Name = deviceIn.Name;
|
||||
device.Connected = deviceIn.Connected;
|
||||
device.Configuration = configuration.Label;
|
||||
device.ConfigurationId = deviceIn.ConfigurationId;
|
||||
|
||||
Device deviceModified = _deviceService.Update(device.Id, device);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user