wellService.CheckWellOwnership rename to wellService.IsCompanyOwnsWell

This commit is contained in:
Фролов 2021-07-27 12:37:10 +05:00
parent 1325663d7e
commit 05cf7244ef
9 changed files with 41 additions and 18 deletions

View File

@ -7,6 +7,7 @@ namespace AsbCloudApp.Services
{
IEnumerable<WellDto> GetWellsByCompany(int idCompany);
IEnumerable<WellDto> GetTransmittingWells(int idCompany);
bool CheckWellOwnership(int idCompany, int wellId);
bool IsCompanyOwnsWell(int idCompany, int wellId);
IEnumerable<WellSectionDto> GetStat(int wellId, int idCompany);
}
}

View File

@ -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<WellSectionDto> GetStat(int wellId, int idCompany)
{
return null;
}
}
}

View File

@ -34,7 +34,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
analyticsService.Setup(s => s.GetWellDepthToDay(It.IsAny<int>()))
.Returns(depthToDayDtos);
wellService.Setup(s => s.CheckWellOwnership(It.IsAny<int>(), It.IsAny<int>()))
wellService.Setup(s => s.IsCompanyOwnsWell(It.IsAny<int>(), It.IsAny<int>()))
.Returns(true);
controller = new AnalyticsController(analyticsService.Object,
@ -94,7 +94,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
{
var wellServiceReturnsFalse = new Mock<IWellService>();
wellServiceReturnsFalse.Setup(s => s.CheckWellOwnership(It.IsAny<int>(), It.IsAny<int>()))
wellServiceReturnsFalse.Setup(s => s.IsCompanyOwnsWell(It.IsAny<int>(), It.IsAny<int>()))
.Returns(false);
var newControllerInstance = new AnalyticsController(analyticsService.Object,

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -38,6 +38,24 @@ namespace AsbCloudWebApi.Controllers
return Ok(wells);
}
[HttpGet("{wellId}/sections")]
[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (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<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetTransmittingWells()