forked from ddrilling/AsbCloudServer
93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/schedule")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class ScheduleController : ControllerBase
|
|
{
|
|
private readonly IScheduleService scheduleService;
|
|
public ScheduleController(IScheduleService service)
|
|
{
|
|
this.scheduleService = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Добавить запись графика работы
|
|
/// </summary>
|
|
/// <param name="value">Объект-запись</param>
|
|
/// <param name="token"></param>
|
|
/// <returns>Идентификатор добавленой записи</returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult<int>> InsertAsync([FromBody] ScheduleDto value, CancellationToken token = default)
|
|
{
|
|
var result = await scheduleService.InsertAsync(value, token).ConfigureAwait(false);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получить все записи графика
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
/// <returns>Список записей графика</returns>
|
|
[HttpGet("all")]
|
|
public async Task<ActionResult<int>> GetAllAsync(CancellationToken token = default)
|
|
{
|
|
var result = await scheduleService.GetAllAsync(token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получить список записей графика для конкретной скважины
|
|
/// </summary>
|
|
/// <param name="idWell">Идентификатор скважины</param>
|
|
/// <param name="workTime">Рабочее время</param>
|
|
/// <param name="token"></param>
|
|
/// <returns>Список записей графика</returns>
|
|
[HttpGet]
|
|
public async Task<ActionResult<int>> GetScheduleAsync(int idWell, DateTimeOffset workTime, CancellationToken token = default)
|
|
{
|
|
var result = await scheduleService.GetSchedule(idWell,workTime, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обновить график
|
|
/// </summary>
|
|
/// <param name="scheduleId">Идентификатор записи</param>
|
|
/// <param name="dto">Элемент графика</param>
|
|
/// <param name="token"></param>
|
|
/// <returns>Количнство обновленных записей</returns>
|
|
[HttpPut("{scheduleId}")]
|
|
public async Task<IActionResult> UpdateAsync(int scheduleId, ScheduleDto dto,
|
|
CancellationToken token = default)
|
|
{
|
|
var result = await scheduleService.UpdateAsync(scheduleId, dto, token)
|
|
.ConfigureAwait(false);
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Удалить запись из графика
|
|
/// </summary>
|
|
/// <param name="scheduleId">Идентификатор записи</param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{scheduleId}")]
|
|
public async Task<ActionResult<int>> DeleteAsync(int scheduleId, CancellationToken token = default)
|
|
{
|
|
var result = await scheduleService.DeleteAsync(scheduleId, token)
|
|
.ConfigureAwait(false);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|