Add device dto and model + add get section from configId
This commit is contained in:
parent
c5b025af1e
commit
1f8fe1b415
15
Manager.Interfaces/DTO/DeviceDTO.cs
Normal file
15
Manager.Interfaces/DTO/DeviceDTO.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class DeviceDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string IpAddress { get; set; }
|
||||
public bool Connected{ get; set; }
|
||||
public DateTime DateCreation{ get; set; }
|
||||
}
|
||||
}
|
||||
63
Manager.Interfaces/Models/Device.cs
Normal file
63
Manager.Interfaces/Models/Device.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Manager.Interfaces.DTO;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Device Information (Tablet)
|
||||
/// </summary>
|
||||
public class Device
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[BsonElement("IpAddress")]
|
||||
[BsonRequired]
|
||||
public string IpAddress { get; set; }
|
||||
|
||||
[BsonElement("ConfigurationId")]
|
||||
[BsonRequired]
|
||||
public string ConfigurationId { get; set; }
|
||||
|
||||
[BsonElement("Connected")]
|
||||
[BsonRequired]
|
||||
public bool Connected { get; set; }
|
||||
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
// BatteryLevel in case of powered devices
|
||||
[BsonElement("BatteryLevel")]
|
||||
public string BatteryLevel { get; set; }
|
||||
|
||||
[BsonElement("LastBatteryLevel")]
|
||||
public DateTime LastBatteryLevel { get; set; }
|
||||
|
||||
// ConnectionLevel wifi strength level
|
||||
[BsonElement("ConnectionLevel")]
|
||||
public string ConnectionLevel { get; set; }
|
||||
|
||||
[BsonElement("LastConnectionLevel")]
|
||||
public DateTime LastConnectionLevel { get; set; }
|
||||
|
||||
|
||||
public DeviceDTO ToDTO()
|
||||
{
|
||||
return new DeviceDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
IpAddress = IpAddress,
|
||||
Connected = Connected,
|
||||
DateCreation = DateCreation
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,21 +48,58 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all section from a specific configuration
|
||||
/// </summary>
|
||||
/// <param name="id">configuration id</param>
|
||||
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[HttpGet("configuration/{id}")]
|
||||
public ObjectResult GetFromConfiguration(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id == null)
|
||||
throw new ArgumentNullException("Param is null");
|
||||
|
||||
List<Section> sections = _sectionService.GetAllFromConfiguration(id);
|
||||
|
||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all subsection (summary) of a specific section
|
||||
/// </summary>
|
||||
/// <param name="id">section id</param>
|
||||
[ProducesResponseType(typeof(List<object>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[HttpGet("{id}/subsections")]
|
||||
public ObjectResult GetAllSectionSubSections(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id == null)
|
||||
throw new ArgumentNullException("Param is null");
|
||||
|
||||
List<Section> sections = _sectionService.GetAllSubSection(id);
|
||||
|
||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
|
||||
@ -18,11 +18,17 @@ namespace Manager.Services
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Sections = database.GetCollection<Section>("Sections");
|
||||
}
|
||||
|
||||
public List<Section> GetAll()
|
||||
{
|
||||
return _Sections.Find(s => !s.IsSubSection).ToList();
|
||||
}
|
||||
|
||||
public List<Section> GetAllFromConfiguration(string configurationId)
|
||||
{
|
||||
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList();
|
||||
}
|
||||
|
||||
public List<Section> GetAllSubSection(string parentId)
|
||||
{
|
||||
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user