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

93 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/message")]
[ApiController]
public class MessageController : ControllerBase
{
private readonly IMessageService messageService;
private readonly IWellService wellService;
public MessageController(IMessageService messageService, IWellService wellService)
{
this.messageService = messageService;
this.wellService = wellService;
}
/// <summary>
/// Выдает список сообщений по скважине
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="categoryids">список категорий</param>
/// <param name="begin">дата начала</param>
/// <param name="end">окончание</param>
/// <param name="skip">для пагинации кол-во записей пропустить</param>
/// <param name="take">для пагинации кол-во записей </param>
/// <param name="searchString"> Строка поиска </param>
/// <param name="isUtc">Даты в формате UTC или часового пояса скважины</param>
/// <param name="token">Токен для отмены задачи</param>
/// <returns>список сообщений по скважине</returns>
[HttpGet]
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetMessagesAsync(int idWell, int skip = 0, int take = 32,
[FromQuery] IEnumerable<int> categoryids = default,
DateTime begin = default, DateTime end = default,
string searchString = default,
bool isUtc = true,
CancellationToken token = default)
{
if (take > 1024)
return BadRequest("limit mast be less then 1024");
if (begin > DateTime.Now)
begin = default;
var result = await messageService.GetMessagesAsync(idWell,
categoryids, begin, end, searchString,
skip, take, isUtc, token).ConfigureAwait(false);
if (result is null || result.Count == 0)
return NoContent();
return Ok(result);
}
/// <summary>
/// Выдает список сообщений по скважине
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token">Токен для отмены задачи</param>
/// <param name="isUtc">Смена дат с UTC формата на часовой пояс скважины</param>
/// <returns>список сообщений по скважине</returns>
[HttpGet]
[Route("datesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell, bool isUtc = true,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)
return Forbid();
var wellMessagesDatesRange = await messageService.GetMessagesDatesRangeAsync(idWell,
isUtc, token);
return Ok(wellMessagesDatesRange);
}
}
}