Фильтрация наработок по массиву ключей бурильщиков

Подгрузка списка бурильщиков в зависимости от ключей скважин
This commit is contained in:
Olga Nemt 2024-04-02 14:16:40 +05:00
parent e4f3adb101
commit ddbd84e933
3 changed files with 43 additions and 7 deletions

View File

@ -14,7 +14,7 @@ public class GetStatRequest: RequestBase
public IEnumerable<int> IdsWells { get; set; } = new List<int>();
/// <summary>
/// id Áóðèëüùèêà
/// ńďčńîę ęëţ÷ĺé áóđčëüůčęîâ
/// </summary>
public int? IdDriller { get; set; }
public IEnumerable<int> IdsDrillers { get; set; } = new List<int>();
}

View File

@ -57,11 +57,11 @@ namespace AsbCloudInfrastructure.Repository
public async Task<IEnumerable<ScheduleDto>> GetPageAsync(GetStatRequest request, CancellationToken token)
{
var idWell = request.IdsWells;
var idDriller = request.IdDriller;
var idsDrillers = request.IdsDrillers;
var query = GetQuery().Where(s => request.IdsWells.Contains(s.IdWell));
if (idDriller is not null)
if (idsDrillers.Any())
{
query.Where(s => s.IdDriller == idDriller);
query = query.Where(s => idsDrillers.Contains(s.IdDriller));
}
var result = await query.ToArrayAsync(token);

View File

@ -1,7 +1,13 @@
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
{
@ -13,8 +19,38 @@ namespace AsbCloudWebApi.Controllers
[Authorize]
public class DrillerController : CrudController<DrillerDto, ICrudRepository<DrillerDto>>
{
public DrillerController(ICrudRepository<DrillerDto> service)
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);
}
}
}