From 05cf7244efe0250f5952880f31785578df4b5277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Tue, 27 Jul 2021 12:37:10 +0500 Subject: [PATCH] wellService.CheckWellOwnership rename to wellService.IsCompanyOwnsWell --- AsbCloudApp/Services/IWellService.cs | 3 ++- AsbCloudInfrastructure/Services/WellService.cs | 6 +++++- .../AnalyticsControllerTests.cs | 4 ++-- .../Controllers/AnalyticsController.cs | 10 +++++----- AsbCloudWebApi/Controllers/DataController.cs | 2 +- AsbCloudWebApi/Controllers/FileController.cs | 6 +++--- .../Controllers/MessageController.cs | 2 +- AsbCloudWebApi/Controllers/ReportController.cs | 8 ++++---- AsbCloudWebApi/Controllers/WellController.cs | 18 ++++++++++++++++++ 9 files changed, 41 insertions(+), 18 deletions(-) diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index 63d42c4a..6d57f34d 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -7,6 +7,7 @@ namespace AsbCloudApp.Services { IEnumerable GetWellsByCompany(int idCompany); IEnumerable GetTransmittingWells(int idCompany); - bool CheckWellOwnership(int idCompany, int wellId); + bool IsCompanyOwnsWell(int idCompany, int wellId); + IEnumerable GetStat(int wellId, int idCompany); } } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 1fd70b44..388f54ab 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -40,7 +40,7 @@ namespace AsbCloudInfrastructure.Services return wells.Select(w => From(w)); } - public bool CheckWellOwnership(int idCompany, int idWell) + public bool IsCompanyOwnsWell(int idCompany, int idWell) => cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany); private static WellDto From(Well well) @@ -56,5 +56,9 @@ namespace AsbCloudInfrastructure.Services return wellDto; } + public IEnumerable GetStat(int wellId, int idCompany) + { + return null; + } } } diff --git a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs index 1aa58d08..f31752f8 100644 --- a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs +++ b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs @@ -34,7 +34,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests analyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny())) .Returns(depthToDayDtos); - wellService.Setup(s => s.CheckWellOwnership(It.IsAny(), It.IsAny())) + wellService.Setup(s => s.IsCompanyOwnsWell(It.IsAny(), It.IsAny())) .Returns(true); controller = new AnalyticsController(analyticsService.Object, @@ -94,7 +94,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests { var wellServiceReturnsFalse = new Mock(); - wellServiceReturnsFalse.Setup(s => s.CheckWellOwnership(It.IsAny(), It.IsAny())) + wellServiceReturnsFalse.Setup(s => s.IsCompanyOwnsWell(It.IsAny(), It.IsAny())) .Returns(false); var newControllerInstance = new AnalyticsController(analyticsService.Object, diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index a1943a95..957dcad3 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -40,7 +40,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperationsByWell(wellId, categoryIds, begin, end, skip, take); @@ -63,7 +63,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId); @@ -89,7 +89,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, @@ -115,7 +115,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperationsSummary(wellId, begin, end); @@ -141,7 +141,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperationsToInterval(wellId, intervalSeconds, workBeginSeconds); diff --git a/AsbCloudWebApi/Controllers/DataController.cs b/AsbCloudWebApi/Controllers/DataController.cs index 6ffe0071..b0290766 100644 --- a/AsbCloudWebApi/Controllers/DataController.cs +++ b/AsbCloudWebApi/Controllers/DataController.cs @@ -59,7 +59,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId); + bool isCompanyOwnsWell = wellService.IsCompanyOwnsWell((int)idCompany, wellId); if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index e4573beb..9e10690c 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -42,7 +42,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var fileInfoCollection = files.Select(f => @@ -87,7 +87,7 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) + if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var filesInfo = fileService.GetFilesInfo(wellId, idCategory, @@ -117,7 +117,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var fileInfo = fileService.GetFileInfo(fileId); diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index 0bf593b7..a5e14b54 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -58,7 +58,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId); + bool isCompanyOwnsWell = wellService.IsCompanyOwnsWell((int)idCompany, wellId); if (!isCompanyOwnsWell) return Forbid(); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index efe63116..8b0668e8 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -68,7 +68,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync); @@ -94,7 +94,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); // TODO: словарь content typoв var relativePath = Path.Combine(reportService.RootPath, $"{wellId}", reportName); @@ -149,7 +149,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); int reportSize = reportService.GetReportPagesCount(wellId, begin, end, stepSeconds, format); @@ -172,7 +172,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCompany, wellId)) + if (!wellService.IsCompanyOwnsWell((int)idCompany, wellId)) return Forbid(); DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(wellId); diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index abfb1c7e..78dda83a 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -38,6 +38,24 @@ namespace AsbCloudWebApi.Controllers return Ok(wells); } + [HttpGet("{wellId}/sections")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetSections(int wellId) + { + var idCompany = User.GetCompanyId(); + + if (idCompany is null) + return NoContent(); + + if (wellService.IsCompanyOwnsWell((int)idCompany, wellId)) + return Forbid(); + + var dto = wellService.GetStat(wellId, (int)idCompany); + + return Ok(dto); + + } + [HttpGet("transmittingWells")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetTransmittingWells()