Add allow anonymous device creation + add wlan and eth differenciation for ipaddress

This commit is contained in:
Thomas Fransolet 2021-07-08 19:14:05 +02:00
parent f03ef70fa3
commit 7be57deb46
3 changed files with 20 additions and 7 deletions

View File

@ -8,7 +8,8 @@ namespace Manager.Interfaces.DTO
{
public string Id { get; set; }
public string Name { get; set; }
public string IpAddress { get; set; }
public string IpAddressWLAN { get; set; }
public string IpAddressETH { get; set; }
public string ConfigurationId { get; set; }
public string Configuration { get; set; }
public bool Connected{ get; set; }

View File

@ -18,9 +18,13 @@ namespace Manager.Interfaces.Models
[BsonElement("Name")]
public string Name { get; set; }
[BsonElement("IpAddress")]
[BsonElement("IpAddressWLAN")]
[BsonRequired]
public string IpAddress { get; set; }
public string IpAddressWLAN { get; set; }
[BsonElement("IpAddressETH")]
[BsonRequired]
public string IpAddressETH { get; set; }
[BsonElement("Configuration")]
public string Configuration { get; set; }
@ -57,7 +61,8 @@ namespace Manager.Interfaces.Models
{
Id = Id,
Name = Name,
IpAddress = IpAddress,
IpAddressWLAN = IpAddressWLAN,
IpAddressETH = IpAddressETH,
Connected = Connected,
Configuration = Configuration,
ConfigurationId = ConfigurationId,
@ -71,7 +76,8 @@ namespace Manager.Interfaces.Models
{
Id = Id,
Name = Name,
IpAddress = IpAddress,
IpAddressWLAN = IpAddressWLAN,
IpAddressETH = IpAddressETH,
Connected = Connected,
Configuration = Configuration,
ConfigurationId = ConfigurationId,

View File

@ -87,6 +87,7 @@ namespace ManagerService.Controllers
/// Create a new device
/// </summary>
/// <param name="newDevice">New device info</param>
[AllowAnonymous]
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
@ -105,11 +106,15 @@ namespace ManagerService.Controllers
if (configuration == null)
throw new KeyNotFoundException("Configuration does not exist");
if (_deviceService.IsExistIpWLAN(newDevice.IpAddressWLAN) || _deviceService.IsExistIpETH(newDevice.IpAddressETH))
throw new InvalidOperationException("Device with same ip already exist in system");
Device device = new Device();
device.Name = newDevice.Name;
device.Configuration = configuration.Label;
device.ConfigurationId = newDevice.ConfigurationId;
device.IpAddress = newDevice.IpAddress;
device.IpAddressETH = newDevice.IpAddressETH;
device.IpAddressWLAN = newDevice.IpAddressWLAN;
device.Connected = newDevice.Connected;
device.ConnectionLevel = newDevice.ConnectionLevel;
device.LastConnectionLevel = newDevice.LastConnectionLevel;
@ -163,7 +168,8 @@ namespace ManagerService.Controllers
// Todo add some verification ?
device.Name = updatedDevice.Name;
device.IpAddress = updatedDevice.IpAddress;
device.IpAddressWLAN = updatedDevice.IpAddressWLAN;
device.IpAddressETH = updatedDevice.IpAddressETH;
device.Connected = updatedDevice.Connected;
device.ConnectionLevel = updatedDevice.ConnectionLevel;
device.LastConnectionLevel = updatedDevice.LastConnectionLevel;