forked from ddrilling/AsbCloudServer
66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
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<ScheduleDto, IScheduleService>
|
|
{
|
|
private readonly IScheduleService scheduleService;
|
|
private readonly IWellService wellService;
|
|
|
|
public ScheduleController(IScheduleService scheduleService, IWellService wellService)
|
|
:base(scheduleService)
|
|
{
|
|
this.scheduleService = service;
|
|
this.wellService = wellService;
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Получить бурильщика работавшего на скважине в определенное время.
|
|
/// </summary>
|
|
/// <param name="idWell">Идентификатор скважины</param>
|
|
/// <param name="workTime">Рабочее время</param>
|
|
/// <param name="token"></param>
|
|
/// <returns>бурильщик</returns>
|
|
[HttpGet("driller")]
|
|
public async Task<ActionResult<DrillerDto>> 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);
|
|
}
|
|
|
|
}
|
|
}
|