From dd9c985e6563982b3ce69b754c33b762e89856c9 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Thu, 13 May 2021 17:50:37 +0500 Subject: [PATCH] =?UTF-8?q?CS2-1:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=B0=D1=82=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IMessageService.cs | 1 + .../Services/MessageService.cs | 32 +++++++++++++++++++ .../Controllers/MessageController.cs | 10 ++++++ 3 files changed, 43 insertions(+) diff --git a/AsbCloudApp/Services/IMessageService.cs b/AsbCloudApp/Services/IMessageService.cs index 69450565..9f3b13d0 100644 --- a/AsbCloudApp/Services/IMessageService.cs +++ b/AsbCloudApp/Services/IMessageService.cs @@ -7,6 +7,7 @@ namespace AsbCloudApp.Services public interface IMessageService { PaginationContainer GetMessages(int wellId, IEnumerable categoryids = null, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32); + IDictionary GetMessagesDatesRange(int wellId); void Insert(string uid, IEnumerable dtos); } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs index 1a6c57a8..f1f0f0e0 100644 --- a/AsbCloudInfrastructure/Services/MessageService.cs +++ b/AsbCloudInfrastructure/Services/MessageService.cs @@ -31,6 +31,23 @@ namespace AsbCloudInfrastructure.Services cacheWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } + private IEnumerable GetMessagesByWell(int wellId) + { + var well = cacheWells.FirstOrDefault(w => w.Id == wellId); + if (well is null) + return null; + + var telemetry = cacheTelemetry.FirstOrDefault(t => t.Id == well.Id); + if (telemetry is null) + return null; + + var messages = from m in db.Messages + where m.IdTelemetry == telemetry.Id + select m; + + return messages; + } + public PaginationContainer GetMessages(int wellId, IEnumerable categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32) { var well = cacheWells.FirstOrDefault(w => w.Id == wellId); @@ -106,6 +123,21 @@ namespace AsbCloudInfrastructure.Services return result; } + public IDictionary GetMessagesDatesRange(int wellId) + { + IEnumerable wellMessages = GetMessagesByWell(wellId) ?? new List(); + + IEnumerable wellMessagesDates = wellMessages.Select(wm => wm.Date); + + IDictionary messagesDatesRange = new Dictionary(); + + messagesDatesRange.Add("From", wellMessagesDates.Any() ? wellMessagesDates.Min() : DateTime.MinValue); + + messagesDatesRange.Add("To", wellMessagesDates.Any() ? wellMessagesDates.Max() : DateTime.MaxValue); + + return messagesDatesRange; + } + public void Insert(string uid, IEnumerable dtos) { if (dtos.Count() == 0) diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index de7ab106..e3c1fbbd 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -41,5 +41,15 @@ namespace AsbCloudWebApi.Controllers var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take); return Ok(result); } + + [HttpGet] + [Route("{wellId}/messagesDatesRange")] + [ProducesResponseType(typeof(IDictionary), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetMessagesDateRange(int wellId) + { + IDictionary wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId); + + return Ok(wellMessagesDatesRange); + } } }