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

73 lines
2.7 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well")]
[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>
/// <returns>список сообщений по скважине</returns>
[HttpGet]
[Route("{idWell}/message")]
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, string searchString = default)
{
if (take > 1024)
return BadRequest("limit mast be less then 1024");
if (begin > DateTime.Now)
begin = default;
var result = messageService.GetMessages(idWell, categoryids, begin, end, searchString, skip, take);
if (result is null || result.Count == 0)
return NoContent();
return Ok(result);
}
[HttpGet]
[Route("{idWell}/messagesDatesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetMessagesDateRangeAsync(int idWell)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell);
if (!isCompanyOwnsWell)
return Forbid();
DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(idWell);
return Ok(wellMessagesDatesRange);
}
}
}