forked from ddrilling/AsbCloudServer
Merge pull request 'Контакты/ Создать метод для предоставления списка контактов по ключу скважины' (#305) from feature/#36879906-get-contacts-by-well-ids into dev
Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/305
This commit is contained in:
commit
770a370d7f
20
AsbCloudApp/Requests/WellContactRequest.cs
Normal file
20
AsbCloudApp/Requests/WellContactRequest.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Запрос на получение контактов
|
||||||
|
/// </summary>
|
||||||
|
public class WellContactRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификаторы скважин
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int> IdsWells { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ключ типа контактов
|
||||||
|
/// </summary>
|
||||||
|
public int? ContactTypeId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.User;
|
using AsbCloudApp.Data.User;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -12,13 +13,12 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IWellContactService
|
public interface IWellContactService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение контактов по ключу скважины и типу контакта
|
/// Получение контактов по параметрам запроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">ключ скважины</param>
|
/// <param name="request">ключ скважины</param>
|
||||||
/// <param name="contactTypeId">тип контакта</param>
|
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<ContactDto>> GetAllAsync(int idWell, int contactTypeId, CancellationToken token);
|
Task<IEnumerable<ContactDto>> GetAllAsync(WellContactRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение контакта по ключу
|
/// Получение контакта по ключу
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.User;
|
using AsbCloudApp.Data.User;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
@ -21,17 +22,22 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ContactDto>> GetAllAsync(int wellId, int contactTypeId, CancellationToken token)
|
public async Task<IEnumerable<ContactDto>> GetAllAsync(WellContactRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.Contacts
|
var query = db.Contacts
|
||||||
.Where(c => c.IdCompanyType == contactTypeId)
|
.Where(c => request.IdsWells.Contains(c.IdWell));
|
||||||
.Where(c => c.IdWell == wellId)
|
|
||||||
.Select(c => c.Adapt<ContactDto>());
|
if (request.ContactTypeId.HasValue)
|
||||||
|
{
|
||||||
|
query = query.Where(c => c.IdCompanyType == request.ContactTypeId);
|
||||||
|
};
|
||||||
|
|
||||||
var entities = await query.AsNoTracking()
|
var entities = await query.AsNoTracking()
|
||||||
.ToArrayAsync(token);
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
return entities;
|
var dtos = entities.Select(c => c.Adapt<ContactDto>());
|
||||||
|
|
||||||
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ContactDto?> GetAsync(int idWell, int id, CancellationToken token)
|
public async Task<ContactDto?> GetAsync(int idWell, int id, CancellationToken token)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.User;
|
using AsbCloudApp.Data.User;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -49,12 +50,43 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("type/{contactTypeId}")]
|
[HttpGet("type/{contactTypeId}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAllAsync(int idWell, int contactTypeId, CancellationToken token)
|
public async Task<IActionResult> GetByTypeAsync(int idWell, int contactTypeId, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await wellContactsRepository.GetAllAsync(idWell, contactTypeId, token);
|
var request = new WellContactRequest()
|
||||||
|
{
|
||||||
|
IdsWells = new int[] { idWell },
|
||||||
|
ContactTypeId = contactTypeId
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await wellContactsRepository.GetAllAsync(request, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение контактов по массиву ключей скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idsWells">ключи скважин</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("/api/well/[controller]")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<ContactDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<int> idsWells, CancellationToken token)
|
||||||
|
{
|
||||||
|
foreach(var idWell in idsWells)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = new WellContactRequest()
|
||||||
|
{
|
||||||
|
IdsWells = idsWells
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await wellContactsRepository.GetAllAsync(request, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user