using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers { [Route("api/schedule")] [ApiController] [Authorize] public class ScheduleController : CrudController { private readonly 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); } /// /// Получить бурильщика работавшего на скважине в определенное время. /// /// Идентификатор скважины /// Рабочее время /// /// бурильщик [HttpGet("driller")] 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); } } }