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; /// /// Справочник бурильщиков /// [Route("api/driller")] [ApiController] [Authorize] public class DrillerController : CrudController> { private IScheduleRepository scheduleRepository; public DrillerController(ICrudRepository service, IScheduleRepository scheduleRepository) : base(service) { this.scheduleRepository = scheduleRepository; } /// /// Получить список бурильщиков по ключам скважин /// /// массив ключей скважин /// token /// все записи [HttpGet("/api/drillers")] [Permission] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] public async Task GetAsync([FromQuery] IEnumerable 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); } }