2022-05-22 21:18:43 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
2022-05-26 15:32:23 +05:00
|
|
|
|
using System.Collections.Generic;
|
2022-05-22 21:18:43 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
[Route("api/schedule")]
|
2022-05-22 21:18:43 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
2022-05-26 13:34:40 +05:00
|
|
|
|
public class ScheduleController : CrudController<ScheduleDto, IScheduleService>
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly IScheduleService scheduleService;
|
2022-05-26 15:32:23 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public ScheduleController(IScheduleService scheduleService, IWellService wellService)
|
2022-05-26 13:34:40 +05:00
|
|
|
|
:base(scheduleService)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
|
|
|
|
this.scheduleService = service;
|
2022-05-26 15:32:23 +05:00
|
|
|
|
this.wellService = wellService;
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 15:32:23 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// список расписаний бурильщиков по скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("byWellId/{idWell}")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ScheduleDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-22 21:18:43 +05:00
|
|
|
|
/// <summary>
|
2022-05-26 13:34:40 +05:00
|
|
|
|
/// Получить бурильщика работавшего на скважине в определенное время.
|
2022-05-22 21:18:43 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Идентификатор скважины</param>
|
2022-05-25 20:19:08 +05:00
|
|
|
|
/// <param name="workTime">Рабочее время</param>
|
2022-05-22 21:18:43 +05:00
|
|
|
|
/// <param name="token"></param>
|
2022-05-26 13:34:40 +05:00
|
|
|
|
/// <returns>бурильщик</returns>
|
|
|
|
|
[HttpGet("driller")]
|
2022-05-26 15:32:23 +05:00
|
|
|
|
public async Task<ActionResult<DrillerDto>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-26 15:32:23 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-05-26 13:34:40 +05:00
|
|
|
|
var result = await scheduleService.GetDrillerAsync(idWell,workTime, token);
|
2022-05-22 21:18:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|