From 0486dd946251881a1e27254ca95f3d22c99a1f24 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 11 Aug 2022 13:55:36 +0500 Subject: [PATCH] Rename ICrudWellRelatedService to IRepositoryWellRelated, and related services --- AsbCloudApp/Services/IDrillFlowChartService.cs | 2 +- AsbCloudApp/Services/IOperationValueService.cs | 12 ------------ ...RelatedService.cs => IRepositoryWellRelated.cs} | 9 +++++---- AsbCloudApp/Services/IScheduleService.cs | 4 ++-- AsbCloudInfrastructure/DependencyInjection.cs | 6 +++--- .../Repository/CrudWellRelatedCacheServiceBase.cs | 2 +- .../Repository/CrudWellRelatedServiceBase.cs | 2 +- .../DrillFlowChartRepository.cs} | 11 ++++------- .../ScheduleRepository.cs} | 9 ++++----- .../WitsRecordRepository.cs | 4 ++-- .../DetectOperations/DetectedOperationService.cs | 4 ++-- .../Services/OperationValueService.cs | 14 -------------- .../ServicesTests/DetectedOperationServiceTest.cs | 2 +- .../ServicesTests/ScheduleServiceTest.cs | 6 +++--- .../Controllers/CrudWellRelatedController.cs | 2 +- .../Controllers/DrillFlowChartController.cs | 4 ++-- .../Controllers/OperationValueController.cs | 4 ++-- AsbCloudWebApi/Controllers/ScheduleController.cs | 6 +++--- 18 files changed, 37 insertions(+), 66 deletions(-) delete mode 100644 AsbCloudApp/Services/IOperationValueService.cs rename AsbCloudApp/Services/{ICrudWellRelatedService.cs => IRepositoryWellRelated.cs} (70%) rename AsbCloudInfrastructure/{Services/DrillFlowChartService.cs => Repository/DrillFlowChartRepository.cs} (83%) rename AsbCloudInfrastructure/{Services/ScheduleService.cs => Repository/ScheduleRepository.cs} (86%) rename AsbCloudInfrastructure/{Services => Repository}/WitsRecordRepository.cs (98%) delete mode 100644 AsbCloudInfrastructure/Services/OperationValueService.cs diff --git a/AsbCloudApp/Services/IDrillFlowChartService.cs b/AsbCloudApp/Services/IDrillFlowChartService.cs index 54e98b71..dbe675d1 100644 --- a/AsbCloudApp/Services/IDrillFlowChartService.cs +++ b/AsbCloudApp/Services/IDrillFlowChartService.cs @@ -9,7 +9,7 @@ namespace AsbCloudApp.Services /// /// /// - public interface IDrillFlowChartService : ICrudWellRelatedService + public interface IDrillFlowChartRepository : IRepositoryWellRelated { /// /// . diff --git a/AsbCloudApp/Services/IOperationValueService.cs b/AsbCloudApp/Services/IOperationValueService.cs deleted file mode 100644 index da097507..00000000 --- a/AsbCloudApp/Services/IOperationValueService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using AsbCloudApp.Data; - -namespace AsbCloudApp.Services -{ - // TODO: Remove this - /// - /// - /// - public interface IOperationValueService : ICrudWellRelatedService - { - } -} diff --git a/AsbCloudApp/Services/ICrudWellRelatedService.cs b/AsbCloudApp/Services/IRepositoryWellRelated.cs similarity index 70% rename from AsbCloudApp/Services/ICrudWellRelatedService.cs rename to AsbCloudApp/Services/IRepositoryWellRelated.cs index b09e21bd..6ce2af0e 100644 --- a/AsbCloudApp/Services/ICrudWellRelatedService.cs +++ b/AsbCloudApp/Services/IRepositoryWellRelated.cs @@ -5,12 +5,13 @@ using System.Threading.Tasks; namespace AsbCloudApp.Services { +#nullable enable /// - /// Сервис получения, добавления, изменения, удаления данных
+ /// Репозиторий получения, добавления, изменения, удаления данных
/// Для сущностей относящихся к скважине ///
/// - public interface ICrudWellRelatedService : ICrudService + public interface IRepositoryWellRelated : ICrudService where Tdto : IId, IWellRelated { /// @@ -19,7 +20,7 @@ namespace AsbCloudApp.Services /// id скважины /// /// emptyList if nothing found - Task> GetByIdWellAsync(int idWell, CancellationToken token); + Task?> GetByIdWellAsync(int idWell, CancellationToken token); /// /// Получение всех записей по нескольким скважинам @@ -27,7 +28,7 @@ namespace AsbCloudApp.Services /// id скважин /// /// emptyList if nothing found - Task> GetByIdWellAsync(IEnumerable idsWells, CancellationToken token); + Task?> GetByIdWellAsync(IEnumerable idsWells, CancellationToken token); } #nullable disable } \ No newline at end of file diff --git a/AsbCloudApp/Services/IScheduleService.cs b/AsbCloudApp/Services/IScheduleService.cs index 4a0d9fb4..375b9103 100644 --- a/AsbCloudApp/Services/IScheduleService.cs +++ b/AsbCloudApp/Services/IScheduleService.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace AsbCloudApp.Services { /// - /// Сервис расписания смен бурильщика + /// Репозиторий расписания смен бурильщика /// - public interface IScheduleService : ICrudWellRelatedService + public interface IScheduleRepository : IRepositoryWellRelated { // TODO: this should be nullable. /// diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index cbcab698..0fb1fc16 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -92,7 +92,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -115,8 +115,8 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient, CrudWellRelatedServiceBase>(); services.AddTransient(); // admin crud services: diff --git a/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheServiceBase.cs b/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheServiceBase.cs index fddcb8aa..f4e60abd 100644 --- a/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheServiceBase.cs +++ b/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheServiceBase.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { #nullable enable - public class CrudWellRelatedCacheServiceBase : CrudCacheServiceBase, ICrudWellRelatedService + public class CrudWellRelatedCacheServiceBase : CrudCacheServiceBase, IRepositoryWellRelated where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated where TEntity : class, IId, IWellRelated { diff --git a/AsbCloudInfrastructure/Repository/CrudWellRelatedServiceBase.cs b/AsbCloudInfrastructure/Repository/CrudWellRelatedServiceBase.cs index eb65cd9d..49bab949 100644 --- a/AsbCloudInfrastructure/Repository/CrudWellRelatedServiceBase.cs +++ b/AsbCloudInfrastructure/Repository/CrudWellRelatedServiceBase.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { #nullable enable - public class CrudWellRelatedServiceBase : CrudServiceBase, ICrudWellRelatedService + public class CrudWellRelatedServiceBase : CrudServiceBase, IRepositoryWellRelated where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated where TEntity : class, IId, IWellRelated { diff --git a/AsbCloudInfrastructure/Services/DrillFlowChartService.cs b/AsbCloudInfrastructure/Repository/DrillFlowChartRepository.cs similarity index 83% rename from AsbCloudInfrastructure/Services/DrillFlowChartService.cs rename to AsbCloudInfrastructure/Repository/DrillFlowChartRepository.cs index 33c6ef78..c23ab1f5 100644 --- a/AsbCloudInfrastructure/Services/DrillFlowChartService.cs +++ b/AsbCloudInfrastructure/Repository/DrillFlowChartRepository.cs @@ -1,7 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Repository; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -10,18 +9,16 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services +namespace AsbCloudInfrastructure.Repository { - public class DrillFlowChartService : CrudWellRelatedServiceBase, - IDrillFlowChartService + public class DrillFlowChartRepository : CrudWellRelatedServiceBase, + IDrillFlowChartRepository { - private readonly IAsbCloudDbContext db; private readonly IWellService wellService; - public DrillFlowChartService(IAsbCloudDbContext context, IWellService wellService) + public DrillFlowChartRepository(IAsbCloudDbContext context, IWellService wellService) : base(context) { - this.db = context; this.wellService = wellService; } diff --git a/AsbCloudInfrastructure/Services/ScheduleService.cs b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs similarity index 86% rename from AsbCloudInfrastructure/Services/ScheduleService.cs rename to AsbCloudInfrastructure/Repository/ScheduleRepository.cs index 06a75a1d..eaca8115 100644 --- a/AsbCloudInfrastructure/Services/ScheduleService.cs +++ b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs @@ -1,7 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Repository; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -9,14 +8,14 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services +namespace AsbCloudInfrastructure.Repository { #nullable enable - public class ScheduleService : CrudWellRelatedServiceBase, IScheduleService + public class ScheduleRepository : CrudWellRelatedServiceBase, IScheduleRepository { private readonly IWellService wellService; - public ScheduleService(IAsbCloudDbContext context, IWellService wellService) + public ScheduleRepository(IAsbCloudDbContext context, IWellService wellService) : base(context, dbSet => dbSet.Include(s => s.Driller)) { this.wellService = wellService; @@ -40,7 +39,7 @@ namespace AsbCloudInfrastructure.Services var time = new TimeOnly(remoteDate.Hour, remoteDate.Minute, remoteDate.Second); var entity = entities.FirstOrDefault(s => - (s.ShiftStart > s.ShiftEnd) ^ + s.ShiftStart > s.ShiftEnd ^ (time >= s.ShiftStart && time < s.ShiftEnd) ); diff --git a/AsbCloudInfrastructure/Services/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs similarity index 98% rename from AsbCloudInfrastructure/Services/WitsRecordRepository.cs rename to AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index e577ac0c..1be9a7de 100644 --- a/AsbCloudInfrastructure/Services/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services +namespace AsbCloudInfrastructure.Repository { public class WitsRecordRepository : IWitsRecordRepository where TEntity : class, ITelemetryData @@ -74,7 +74,7 @@ namespace AsbCloudInfrastructure.Services var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours; var entities = dtos .DistinctBy(d => d.DateTime) - .Select(dto => Convert(dto, idTelemetry, timezoneHours)); + .Select(dto => Convert(dto, idTelemetry, timezoneHours)); dbset.AddRange(entities); return db.SaveChangesAsync(token); } diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index 5b2d2071..3b9b1379 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -38,10 +38,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations private readonly IAsbCloudDbContext db; private readonly IWellService wellService; private readonly IOperationValueService operationValueService; - private readonly IScheduleService scheduleService; + private readonly IScheduleRepository scheduleService; public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService, - IOperationValueService operationValueService, IScheduleService scheduleService) + IOperationValueService operationValueService, IScheduleRepository scheduleService) { this.db = db; this.wellService = wellService; diff --git a/AsbCloudInfrastructure/Services/OperationValueService.cs b/AsbCloudInfrastructure/Services/OperationValueService.cs deleted file mode 100644 index 05d36f62..00000000 --- a/AsbCloudInfrastructure/Services/OperationValueService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using AsbCloudApp.Data; -using AsbCloudApp.Services; -using AsbCloudDb.Model; -using AsbCloudInfrastructure.Repository; - -namespace AsbCloudInfrastructure.Services -{ - public class OperationValueService : CrudWellRelatedServiceBase, IOperationValueService - { - public OperationValueService(IAsbCloudDbContext context) : base(context) - { - } - } -} diff --git a/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs index 03bcff27..cbf687c5 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/DetectedOperationServiceTest.cs @@ -125,7 +125,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests wellServiceMock.Setup(s => s.GetTimezone(It.IsAny())).Returns(timezone); wellServiceMock.Setup(s => s.GetOrDefaultAsync(It.IsAny(),CancellationToken.None)).Returns(Task.Run(() => wellDto)); var operationValueService = new OperationValueService(context); - var scheduleService = new ScheduleService(context, wellServiceMock.Object); + var scheduleService = new ScheduleRepository(context, wellServiceMock.Object); service = new DetectedOperationService(context, wellServiceMock.Object, operationValueService, scheduleService); request = new DetectedOperationRequest diff --git a/AsbCloudWebApi.Tests/ServicesTests/ScheduleServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/ScheduleServiceTest.cs index 9c707ef0..46d40eb0 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/ScheduleServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/ScheduleServiceTest.cs @@ -1,7 +1,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Services; +using AsbCloudInfrastructure.Repository; using Moq; using System; using System.Linq; @@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests public class ScheduleServiceTest { private readonly AsbCloudDbContext context; - private readonly ScheduleService scheduleService; + private readonly ScheduleRepository scheduleService; private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" }; private Cluster clater = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() }; private Schedule scd = new Schedule @@ -71,7 +71,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests var timezone = new SimpleTimezoneDto { Hours = 5 }; var wellServiceMock = new Mock(); wellServiceMock.Setup(s => s.GetTimezone(It.IsAny())).Returns(timezone); - scheduleService = new ScheduleService(context, wellServiceMock.Object); + scheduleService = new ScheduleRepository(context, wellServiceMock.Object); AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); } diff --git a/AsbCloudWebApi/Controllers/CrudWellRelatedController.cs b/AsbCloudWebApi/Controllers/CrudWellRelatedController.cs index 3fd0140a..236d13e1 100644 --- a/AsbCloudWebApi/Controllers/CrudWellRelatedController.cs +++ b/AsbCloudWebApi/Controllers/CrudWellRelatedController.cs @@ -20,7 +20,7 @@ namespace AsbCloudWebApi.Controllers [Authorize] public abstract class CrudWellRelatedController : CrudController where T : IId, IWellRelated - where TService : ICrudWellRelatedService + where TService : IRepositoryWellRelated { protected readonly IWellService wellService; diff --git a/AsbCloudWebApi/Controllers/DrillFlowChartController.cs b/AsbCloudWebApi/Controllers/DrillFlowChartController.cs index cc4d4b52..99c2875d 100644 --- a/AsbCloudWebApi/Controllers/DrillFlowChartController.cs +++ b/AsbCloudWebApi/Controllers/DrillFlowChartController.cs @@ -15,11 +15,11 @@ namespace AsbCloudWebApi.Controllers [ApiController] [Route("api/[controller]")] [Authorize] - public class DrillFlowChartController : CrudWellRelatedController + public class DrillFlowChartController : CrudWellRelatedController { private readonly ITelemetryService telemetryService; - public DrillFlowChartController(IWellService wellService, IDrillFlowChartService service, + public DrillFlowChartController(IWellService wellService, IDrillFlowChartRepository service, ITelemetryService telemetryService) : base(wellService, service) { diff --git a/AsbCloudWebApi/Controllers/OperationValueController.cs b/AsbCloudWebApi/Controllers/OperationValueController.cs index a4c2fbe4..6e9c312b 100644 --- a/AsbCloudWebApi/Controllers/OperationValueController.cs +++ b/AsbCloudWebApi/Controllers/OperationValueController.cs @@ -11,9 +11,9 @@ namespace AsbCloudWebApi.Controllers [Route("api/operationValue")] [ApiController] [Authorize] - public class OperationValueController : CrudWellRelatedController + public class OperationValueController : CrudWellRelatedController> { - public OperationValueController(IOperationValueService service, IWellService wellService) : base(wellService, service) + public OperationValueController(IRepositoryWellRelated service, IWellService wellService) : base(wellService, service) { } } diff --git a/AsbCloudWebApi/Controllers/ScheduleController.cs b/AsbCloudWebApi/Controllers/ScheduleController.cs index 4e4a9a58..e0c0752a 100644 --- a/AsbCloudWebApi/Controllers/ScheduleController.cs +++ b/AsbCloudWebApi/Controllers/ScheduleController.cs @@ -14,11 +14,11 @@ namespace AsbCloudWebApi.Controllers [Route("api/schedule")] [ApiController] [Authorize] - public class ScheduleController : CrudWellRelatedController + public class ScheduleController : CrudWellRelatedController { - private readonly IScheduleService scheduleService; + private readonly IScheduleRepository scheduleService; - public ScheduleController(IScheduleService scheduleService, IWellService wellService) + public ScheduleController(IScheduleRepository scheduleService, IWellService wellService) : base(wellService, scheduleService) { this.scheduleService = service;