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

57 lines
1.9 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Справочник бурильщиков
/// </summary>
[Route("api/driller")]
[ApiController]
[Authorize]
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
{
private IScheduleRepository scheduleRepository;
public DrillerController(ICrudRepository<DrillerDto> service, IScheduleRepository scheduleRepository)
: base(service)
{
this.scheduleRepository = scheduleRepository;
}
/// <summary>
/// Получить список бурильщиков по ключам скважин
/// </summary>
/// <param name="idsWells">массив ключей скважин</param>
/// <param name="token">token</param>
/// <returns>все записи</returns>
[HttpGet("/api/drillers")]
[Permission]
[ProducesResponseType(typeof(IEnumerable<DrillerDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAsync([FromQuery] IEnumerable<int> idsWells, CancellationToken token)
{
var request = new GetStatRequest()
{
IdsWells = idsWells,
};
var schedulePage = await scheduleRepository.GetPageAsync(request, token);
var drillers = schedulePage
.Select(s => s.Driller)
.Where(d => d is not null)
.GroupBy(d => d!.Id)
.Select(group => group.First())
.OrderBy(d => d!.Surname);
return Ok(drillers);
}
}
}