feat(api): добавлена фильтрация для подпроцесса, тнк, работы по ИД родителя
This commit is contained in:
10
PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs
Normal file
10
PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
|
{
|
||||||
|
public class SubprocessQuery
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Фильтр по ИД процесса
|
||||||
|
/// </summary>
|
||||||
|
public Guid? ProcessId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
10
PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs
Normal file
10
PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
|
{
|
||||||
|
public class TnkQuery
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Фильтр по ИД подпроцесса
|
||||||
|
/// </summary>
|
||||||
|
public Guid? SubprocessId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,5 +16,10 @@
|
|||||||
/// Поиск по ИД
|
/// Поиск по ИД
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid? Id { get; set; }
|
public Guid? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Фильтр по ИД ТНК
|
||||||
|
/// </summary>
|
||||||
|
public Guid? TnkId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,54 +46,22 @@ namespace PARR.API.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Создать подпроцесс
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost(ApiRoutes.Subprocess.Create)]
|
|
||||||
public async Task<IActionResult> Create([FromBody] SubprocessRequest request)
|
|
||||||
{
|
|
||||||
var resultValidate = await validator.ValidateAsync(request);
|
|
||||||
if (!resultValidate.IsValid)
|
|
||||||
return BadRequest(new Response(resultValidate.Errors));
|
|
||||||
|
|
||||||
var existName = await subprocessService.Get().FirstOrDefaultAsync(t => t.Name == request.Name);
|
|
||||||
if (existName != null)
|
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Name), Message = $"Подпроцесс с именем \"{request.Name}\" уже существует." } }));
|
|
||||||
|
|
||||||
var subprocess = new Subprocess
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Name = request.Name,
|
|
||||||
EsppId = request.EsppId,
|
|
||||||
ProcessId = request.ProcessId,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!await subprocessService.CreateAsync(subprocess) || !await subprocessService.CommitAsync())
|
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при записи нового подпроцесса в базу данных" } }));
|
|
||||||
|
|
||||||
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил подпроцесс: {subprocess.Name}, {subprocess.EsppId}, {subprocess.ProcessId}");
|
|
||||||
|
|
||||||
var locationUri = uriService.GetUri(ApiRoutes.Subprocess.Get, ApiRoutes.Subprocess.getParam, subprocess.Id);
|
|
||||||
|
|
||||||
return Created(locationUri, new Response<SubprocessResponse>(mapper.Map<SubprocessResponse>(subprocess), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список подпроцессов постранично
|
/// Список подпроцессов постранично
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="paginationQuery"></param>
|
/// <param name="paginationQuery"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.Subprocess.GetAll)]
|
[HttpGet(ApiRoutes.Subprocess.GetAll)]
|
||||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery)
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] SubprocessQuery filter)
|
||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<Subprocess> query = subprocessService.Get()
|
IQueryable<Subprocess> query = subprocessService.Get()
|
||||||
.OrderBy(t => t.Name);
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
|
if (filter.ProcessId.HasValue)
|
||||||
|
query = query.Where(t => t.ProcessId == filter.ProcessId.Value);
|
||||||
|
|
||||||
var subprocesses = await subprocessService.GetPage(query, paginationFilter).ToListAsync();
|
var subprocesses = await subprocessService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!subprocesses.Any())
|
if (!subprocesses.Any())
|
||||||
@@ -147,6 +115,44 @@ namespace PARR.API.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создать подпроцесс
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(ApiRoutes.Subprocess.Create)]
|
||||||
|
public async Task<IActionResult> Create([FromBody] SubprocessRequest request)
|
||||||
|
{
|
||||||
|
var resultValidate = await validator.ValidateAsync(request);
|
||||||
|
if (!resultValidate.IsValid)
|
||||||
|
return BadRequest(new Response(resultValidate.Errors));
|
||||||
|
|
||||||
|
var existName = await subprocessService.Get().FirstOrDefaultAsync(t => t.Name == request.Name);
|
||||||
|
if (existName != null)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Name), Message = $"Подпроцесс с именем \"{request.Name}\" уже существует." } }));
|
||||||
|
|
||||||
|
var subprocess = new Subprocess
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = request.Name,
|
||||||
|
EsppId = request.EsppId,
|
||||||
|
ProcessId = request.ProcessId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!await subprocessService.CreateAsync(subprocess) || !await subprocessService.CommitAsync())
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при записи нового подпроцесса в базу данных" } }));
|
||||||
|
|
||||||
|
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил подпроцесс: {subprocess.Name}, {subprocess.EsppId}, {subprocess.ProcessId}");
|
||||||
|
|
||||||
|
var locationUri = uriService.GetUri(ApiRoutes.Subprocess.Get, ApiRoutes.Subprocess.getParam, subprocess.Id);
|
||||||
|
|
||||||
|
return Created(locationUri, new Response<SubprocessResponse>(mapper.Map<SubprocessResponse>(subprocess), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить подпроцесс
|
/// Обновить подпроцесс
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -46,54 +46,22 @@ namespace PARR.API.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Создать ТНК
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost(ApiRoutes.Tnk.Create)]
|
|
||||||
public async Task<IActionResult> Create([FromBody] TnkRequest request)
|
|
||||||
{
|
|
||||||
var resultValidate = await validator.ValidateAsync(request);
|
|
||||||
if (!resultValidate.IsValid)
|
|
||||||
return BadRequest(new Response(resultValidate.Errors));
|
|
||||||
|
|
||||||
var existName = await tnkService.Get().FirstOrDefaultAsync(t => t.Name == request.Name);
|
|
||||||
if (existName != null)
|
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Name), Message = $"Вид работы с именем \"{request.Name}\" уже существует." } }));
|
|
||||||
|
|
||||||
var tnk = new Tnk
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Name = request.Name,
|
|
||||||
EsppId = request.EsppId,
|
|
||||||
SubprocessId = request.SubprocessId,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!await tnkService.CreateAsync(tnk) || !await tnkService.CommitAsync())
|
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при записи новой ТНК в базу данных" } }));
|
|
||||||
|
|
||||||
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил ТНК: {tnk.Name}, {tnk.EsppId}, {tnk.SubprocessId}");
|
|
||||||
|
|
||||||
var locationUri = uriService.GetUri(ApiRoutes.Tnk.Get, ApiRoutes.Tnk.getParam, tnk.Id);
|
|
||||||
|
|
||||||
return Created(locationUri, new Response<TnkResponse>(mapper.Map<TnkResponse>(tnk), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список ТНК постранично
|
/// Список ТНК постранично
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="paginationQuery"></param>
|
/// <param name="paginationQuery"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.Tnk.GetAll)]
|
[HttpGet(ApiRoutes.Tnk.GetAll)]
|
||||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery)
|
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] TnkQuery filter)
|
||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||||
|
|
||||||
IQueryable<Tnk> query = tnkService.Get()
|
IQueryable<Tnk> query = tnkService.Get()
|
||||||
.OrderBy(t => t.Name);
|
.OrderBy(t => t.Name);
|
||||||
|
|
||||||
|
if (filter.SubprocessId.HasValue)
|
||||||
|
query = query.Where(t => t.SubprocessId == filter.SubprocessId);
|
||||||
|
|
||||||
var tnks = await tnkService.GetPage(query, paginationFilter).ToListAsync();
|
var tnks = await tnkService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!tnks.Any())
|
if (!tnks.Any())
|
||||||
@@ -147,6 +115,42 @@ namespace PARR.API.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создать ТНК
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(ApiRoutes.Tnk.Create)]
|
||||||
|
public async Task<IActionResult> Create([FromBody] TnkRequest request)
|
||||||
|
{
|
||||||
|
var resultValidate = await validator.ValidateAsync(request);
|
||||||
|
if (!resultValidate.IsValid)
|
||||||
|
return BadRequest(new Response(resultValidate.Errors));
|
||||||
|
|
||||||
|
var existName = await tnkService.Get().FirstOrDefaultAsync(t => t.Name == request.Name);
|
||||||
|
if (existName != null)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(request.Name), Message = $"Вид работы с именем \"{request.Name}\" уже существует." } }));
|
||||||
|
|
||||||
|
var tnk = new Tnk
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = request.Name,
|
||||||
|
EsppId = request.EsppId,
|
||||||
|
SubprocessId = request.SubprocessId,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!await tnkService.CreateAsync(tnk) || !await tnkService.CommitAsync())
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при записи новой ТНК в базу данных" } }));
|
||||||
|
|
||||||
|
logger.LogInformation($"Пользователь {User.Identity?.Name} добавил ТНК: {tnk.Name}, {tnk.EsppId}, {tnk.SubprocessId}");
|
||||||
|
|
||||||
|
var locationUri = uriService.GetUri(ApiRoutes.Tnk.Get, ApiRoutes.Tnk.getParam, tnk.Id);
|
||||||
|
|
||||||
|
return Created(locationUri, new Response<TnkResponse>(mapper.Map<TnkResponse>(tnk), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить ТНК
|
/// Обновить ТНК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
if (filter.Id.HasValue)
|
if (filter.Id.HasValue)
|
||||||
query = query.Where(t => t.Id == filter.Id);
|
query = query.Where(t => t.Id == filter.Id);
|
||||||
|
|
||||||
|
if (filter.TnkId.HasValue)
|
||||||
|
query = query.Where(t => t.TnkId == filter.TnkId.Value);
|
||||||
|
|
||||||
var works = await workService.GetPage(query, paginationFilter).ToListAsync();
|
var works = await workService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user