diff --git a/API/Controller/Admin/OnlineDevicesController.cs b/API/Controller/Admin/OnlineDevicesController.cs index 3b80c95d..e15928c7 100644 --- a/API/Controller/Admin/OnlineDevicesController.cs +++ b/API/Controller/Admin/OnlineDevicesController.cs @@ -1,71 +1,71 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using OpenShock.Common.Models; -using OpenShock.Common.Redis; -using OpenShock.Common.Serialization; -using OpenShock.ServicesCommon.Utils; -using Semver; -using System.Net; -using System.Text.Json.Serialization; - -namespace OpenShock.API.Controller.Admin; - -public sealed partial class AdminController -{ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using OpenShock.Common.Models; +using OpenShock.Common.Redis; +using OpenShock.Common.Serialization; +using OpenShock.ServicesCommon.Utils; +using Semver; +using System.Net; +using System.Text.Json.Serialization; + +namespace OpenShock.API.Controller.Admin; + +public sealed partial class AdminController +{ /// /// Gets all online devices /// - /// All online devices - /// Unauthorized - [HttpGet(Name = "GetOnlineDevices")] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.Unauthorized)] - public async Task> Get() - { - var devicesOnline = _redis.RedisCollection(false); - - var allOnlineDevices = await devicesOnline.ToListAsync(); - var dbLookup = await _db.Devices.Where(x => allOnlineDevices.Select(y => y.Id) - .Contains(x.Id)).Select( - x => - new - { - x.Id, - x.Name, - Owner = new GenericIni - { - Id = x.OwnerNavigation.Id, - Image = x.OwnerNavigation.GetImage(), - Name = x.OwnerNavigation.Name - } - }).ToListAsync(); - - return new BaseResponse - { - Data = allOnlineDevices.Select(x => - { - var dbItem = dbLookup.First(y => y.Id == x.Id); - return new AdminOnlineDeviceResponse - { - Id = x.Id, - FirmwareVersion = x.FirmwareVersion, - Gateway = x.Gateway, - Owner = dbItem.Owner, - Name = dbItem.Name - }; - }) - }; - } - - public class AdminOnlineDeviceResponse - { - public required Guid Id { get; set; } - public required string Name { get; set; } - public required GenericIni Owner { get; set; } - - [JsonConverter(typeof(SemVersionJsonConverter))] - public SemVersion? FirmwareVersion { get; set; } - - public string? Gateway { get; set; } - } + /// All online devices + /// Unauthorized + [HttpGet("monitoring/onlineDevices", Name = "GetOnlineDevices")] + [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.Unauthorized)] + public async Task> Get() + { + var devicesOnline = _redis.RedisCollection(false); + + var allOnlineDevices = await devicesOnline.ToListAsync(); + var dbLookup = await _db.Devices.Where(x => allOnlineDevices.Select(y => y.Id) + .Contains(x.Id)).Select( + x => + new + { + x.Id, + x.Name, + Owner = new GenericIni + { + Id = x.OwnerNavigation.Id, + Image = x.OwnerNavigation.GetImage(), + Name = x.OwnerNavigation.Name + } + }).ToListAsync(); + + return new BaseResponse + { + Data = allOnlineDevices.Select(x => + { + var dbItem = dbLookup.First(y => y.Id == x.Id); + return new AdminOnlineDeviceResponse + { + Id = x.Id, + FirmwareVersion = x.FirmwareVersion, + Gateway = x.Gateway, + Owner = dbItem.Owner, + Name = dbItem.Name + }; + }) + }; + } + + public class AdminOnlineDeviceResponse + { + public required Guid Id { get; set; } + public required string Name { get; set; } + public required GenericIni Owner { get; set; } + + [JsonConverter(typeof(SemVersionJsonConverter))] + public SemVersion? FirmwareVersion { get; set; } + + public string? Gateway { get; set; } + } } \ No newline at end of file diff --git a/LiveControlGateway/Startup.cs b/LiveControlGateway/Startup.cs index 87fea847..e0fdd212 100644 --- a/LiveControlGateway/Startup.cs +++ b/LiveControlGateway/Startup.cs @@ -113,9 +113,6 @@ public void ConfigureServices(IServiceCollection services) redis.Connection.CreateIndex(typeof(LcgNode)); services.AddSingleton(redis); - // TODO: Is this needed? - //services.AddStackExchangeRedisExtensions(redisConf); - services.AddMemoryCache(); services.AddHttpContextAccessor();