From c568fafa8f292fc3e03e136bfa9d323b0fe7c203 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 26 May 2022 15:32:23 +0500 Subject: [PATCH] Add ScheduleController.GetByIdWellAsync(..) --- AsbCloudApp/Services/IScheduleService.cs | 1 + .../Services/ScheduleService.cs | 10 ++++++ .../Controllers/ScheduleController.cs | 31 +++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/AsbCloudApp/Services/IScheduleService.cs b/AsbCloudApp/Services/IScheduleService.cs index 43eec254..5037ef43 100644 --- a/AsbCloudApp/Services/IScheduleService.cs +++ b/AsbCloudApp/Services/IScheduleService.cs @@ -8,6 +8,7 @@ namespace AsbCloudApp.Services { public interface IScheduleService : ICrudService { + Task> GetByIdWellAsync(int idWell, CancellationToken token = default); Task GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default); } } diff --git a/AsbCloudInfrastructure/Services/ScheduleService.cs b/AsbCloudInfrastructure/Services/ScheduleService.cs index 15e7550b..88f035c2 100644 --- a/AsbCloudInfrastructure/Services/ScheduleService.cs +++ b/AsbCloudInfrastructure/Services/ScheduleService.cs @@ -4,6 +4,7 @@ using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -21,6 +22,15 @@ namespace AsbCloudInfrastructure.Services this.wellService = wellService; } + public async Task> GetByIdWellAsync(int idWell, CancellationToken token = default) + { + var entities = await GetQueryWithIncludes() + .Where(s => s.IdWell == idWell) + .ToListAsync(token); + var dtos = entities.Select(Convert); + return dtos; + } + public async Task GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default) { var hoursOffset = wellService.GetTimezone(idWell).Hours; diff --git a/AsbCloudWebApi/Controllers/ScheduleController.cs b/AsbCloudWebApi/Controllers/ScheduleController.cs index 0239b4cb..38669886 100644 --- a/AsbCloudWebApi/Controllers/ScheduleController.cs +++ b/AsbCloudWebApi/Controllers/ScheduleController.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -14,12 +15,34 @@ namespace AsbCloudWebApi.Controllers public class ScheduleController : CrudController { private readonly IScheduleService scheduleService; - public ScheduleController(IScheduleService scheduleService) + private readonly IWellService wellService; + + public ScheduleController(IScheduleService scheduleService, IWellService wellService) :base(scheduleService) { this.scheduleService = service; + this.wellService = wellService; } + /// + /// список расписаний бурильщиков по скважине + /// + /// + /// + /// + [HttpGet("byWellId/{idWell}")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetByIdWellAsync(int idWell, CancellationToken token) + { + var idCompany = User.GetCompanyId(); + if(idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + return Forbid(); + + var result = await scheduleService.GetByIdWellAsync(idWell, token); + return Ok(result); + } + + /// /// Получить бурильщика работавшего на скважине в определенное время. /// @@ -28,8 +51,12 @@ namespace AsbCloudWebApi.Controllers /// /// бурильщик [HttpGet("driller")] - public async Task> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default) + public async Task> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token) { + var idCompany = User.GetCompanyId(); + if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) + return Forbid(); + var result = await scheduleService.GetDrillerAsync(idWell,workTime, token); return Ok(result); }