using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
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;
}
///
/// Выдает список сообщений по скважине
///
/// id скважины
/// список категорий
/// дата начала
/// окончание
/// для пагинации кол-во записей пропустить
/// для пагинации кол-во записей
/// список сообщений по скважине
[HttpGet]
[Route("{wellId}/message")]
[ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessage(int wellId, int skip = 0, int take = 32, [FromQuery] IEnumerable categoryids = default, DateTime begin = default, DateTime end = default)
{
if (take > 1024)
return BadRequest("limit mast be less then 1024");
if (begin > DateTime.Now)
begin = default;
var result = messageService.GetMessages(wellId, categoryids, begin, end, skip, take);
if (result is null || result.Count == 0)
return NoContent();
return Ok(result);
}
[HttpGet]
[Route("{wellId}/messagesDatesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessagesDateRange(int wellId)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId);
if (!isCompanyOwnsWell)
return Forbid();
DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId);
return Ok(wellMessagesDatesRange);
}
}
}