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

72 lines
2.7 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;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well")]
[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>
/// <returns>список сообщений по скважине</returns>
[HttpGet]
2021-07-27 14:43:30 +05:00
[Route("{idWell}/message")]
2021-04-23 10:21:25 +05:00
[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)
2021-04-23 10:21:25 +05:00
{
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();
2021-04-23 10:21:25 +05:00
return Ok(result);
}
[HttpGet]
2021-07-27 14:43:30 +05:00
[Route("{idWell}/messagesDatesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
2021-07-27 14:43:30 +05:00
public IActionResult GetMessagesDateRange(int idWell)
{
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 = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
2021-07-21 15:29:19 +05:00
2021-07-21 15:22:58 +05:00
if (!isCompanyOwnsWell)
return Forbid();
2021-07-27 14:43:30 +05:00
DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(idWell);
return Ok(wellMessagesDatesRange);
}
2021-04-23 10:21:25 +05:00
}
}