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

85 lines
3.4 KiB
C#
Raw Normal View History

2021-04-23 10:21:25 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
2021-04-23 10:21:25 +05:00
namespace AsbCloudWebApi.Controllers
{
2021-08-17 09:39:05 +05:00
[Route("api/well/{idWell}/message")]
2021-04-23 10:21:25 +05:00
[ApiController]
public class MessageController : ControllerBase
{
private readonly IMessageService messageService;
private readonly IWellService wellService;
2021-04-23 10:21:25 +05:00
public MessageController(IMessageService messageService, IWellService wellService)
2021-04-23 10:21:25 +05:00
{
this.messageService = messageService;
this.wellService = wellService;
2021-04-23 10:21:25 +05:00
}
/// <summary>
/// Выдает список сообщений по скважине
/// </summary>
2021-07-27 14:43:30 +05:00
/// <param name="idWell">id скважины</param>
2021-04-23 10:21:25 +05:00
/// <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="token">Токен для отмены задачи</param>
2021-04-23 10:21:25 +05:00
/// <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,
CancellationToken token = default)
2021-04-23 10:21:25 +05:00
{
if (take > 1024)
return BadRequest("limit mast be less then 1024");
var result = await messageService.GetMessagesAsync(idWell,
categoryids, begin, end, searchString,
skip, take, token).ConfigureAwait(false);
if (result is null || result.Count == 0)
return NoContent();
2021-04-23 10:21:25 +05:00
return Ok(result);
}
/// <summary>
/// Выдает список сообщений по скважине
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token">Токен для отмены задачи</param>
/// <returns>список сообщений по скважине</returns>
[HttpGet]
2021-08-17 09:39:05 +05:00
[Route("datesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell, CancellationToken token = default)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
2021-07-21 15:29:19 +05:00
2021-07-21 15:22:58 +05:00
if (!isCompanyOwnsWell)
return Forbid();
var wellMessagesDatesRange = wellService.GetDatesRange(idWell);
return Ok(wellMessagesDatesRange);
}
2021-04-23 10:21:25 +05:00
}
}