DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AdminScheduleController.cs

94 lines
3.7 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/admin/schedule")]
[ApiController]
[Authorize]
public class AdminScheduleController : ControllerBase
{
private readonly IScheduleService scheduleService;
public AdminScheduleController(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="dateStart">Начало периода</param>
/// <param name="dateEnd">Конец периода</param>
/// <param name="token"></param>
/// <returns>Список записей графика</returns>
[HttpGet]
public async Task<ActionResult<int>> GetScheduleAsync(int idWell, DateTimeOffset dateStart, DateTimeOffset dateEnd, CancellationToken token = default)
{
var result = await scheduleService.GetSchedule(idWell,dateStart,dateEnd, 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);
}
}
}