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("{idWell}/message")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable 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 IActionResult GetMessagesDateRange(int idWell) { int? idCompany = User.GetCompanyId(); if (idCompany is null) return Forbid(); bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell); if (!isCompanyOwnsWell) return Forbid(); DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(idWell); return Ok(wellMessagesDatesRange); } } }