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

56 lines
2.2 KiB
C#

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;
public MessageController(IMessageService messageService)
{
this.messageService = messageService;
}
/// <summary>
/// Выдает список сообщений по скважине
/// </summary>
/// <param name="wellId">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("{wellId}/message")]
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessage(int wellId, int skip = 0, int take = 32, [FromQuery] IEnumerable<int> 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);
return Ok(result);
}
[HttpGet]
[Route("{wellId}/messagesDatesRange")]
[ProducesResponseType(typeof(IDictionary<string, DateTime>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessagesDateRange(int wellId)
{
IDictionary<string, DateTime> wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId);
return Ok(wellMessagesDatesRange);
}
}
}