diff --git a/PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs
new file mode 100644
index 00000000..fb5f3d7b
--- /dev/null
+++ b/PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs
@@ -0,0 +1,10 @@
+namespace PARR.API.Contracts.V1.Requests.Queries
+{
+ public class SubprocessQuery
+ {
+ ///
+ /// Фильтр по ИД процесса
+ ///
+ public Guid? ProcessId { get; set; }
+ }
+}
diff --git a/PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs
new file mode 100644
index 00000000..d799d9ec
--- /dev/null
+++ b/PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs
@@ -0,0 +1,10 @@
+namespace PARR.API.Contracts.V1.Requests.Queries
+{
+ public class TnkQuery
+ {
+ ///
+ /// Фильтр по ИД подпроцесса
+ ///
+ public Guid? SubprocessId { get; set; }
+ }
+}
diff --git a/PARR.API/Contracts/V1/Requests/Queries/WorkGetAllQuery.cs b/PARR.API/Contracts/V1/Requests/Queries/WorkGetAllQuery.cs
index 53135642..821797d0 100644
--- a/PARR.API/Contracts/V1/Requests/Queries/WorkGetAllQuery.cs
+++ b/PARR.API/Contracts/V1/Requests/Queries/WorkGetAllQuery.cs
@@ -16,5 +16,10 @@
/// Поиск по ИД
///
public Guid? Id { get; set; }
+
+ ///
+ /// Фильтр по ИД ТНК
+ ///
+ public Guid? TnkId { get; set; }
}
}
diff --git a/PARR.API/Controllers/V1/SubprocessController.cs b/PARR.API/Controllers/V1/SubprocessController.cs
index c2b48e60..8b866525 100644
--- a/PARR.API/Controllers/V1/SubprocessController.cs
+++ b/PARR.API/Controllers/V1/SubprocessController.cs
@@ -46,54 +46,22 @@ namespace PARR.API.Controllers.V1
}
- ///
- /// Создать подпроцесс
- ///
- ///
- ///
- [HttpPost(ApiRoutes.Subprocess.Create)]
- public async Task 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 { 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 { 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(mapper.Map(subprocess), true));
- }
-
-
///
/// Список подпроцессов постранично
///
///
///
[HttpGet(ApiRoutes.Subprocess.GetAll)]
- public async Task GetAll([FromQuery] PaginationQuery paginationQuery)
+ public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] SubprocessQuery filter)
{
var paginationFilter = mapper.Map(paginationQuery);
IQueryable query = subprocessService.Get()
.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();
if (!subprocesses.Any())
@@ -147,6 +115,44 @@ namespace PARR.API.Controllers.V1
}
+
+ ///
+ /// Создать подпроцесс
+ ///
+ ///
+ ///
+ [HttpPost(ApiRoutes.Subprocess.Create)]
+ public async Task 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 { 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 { 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(mapper.Map(subprocess), true));
+ }
+
+
+
+
///
/// Обновить подпроцесс
///
diff --git a/PARR.API/Controllers/V1/TnkController.cs b/PARR.API/Controllers/V1/TnkController.cs
index 8980f3d4..a0adc67e 100644
--- a/PARR.API/Controllers/V1/TnkController.cs
+++ b/PARR.API/Controllers/V1/TnkController.cs
@@ -46,54 +46,22 @@ namespace PARR.API.Controllers.V1
}
- ///
- /// Создать ТНК
- ///
- ///
- ///
- [HttpPost(ApiRoutes.Tnk.Create)]
- public async Task 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 { 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 { 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(mapper.Map(tnk), true));
- }
-
-
///
/// Список ТНК постранично
///
///
///
[HttpGet(ApiRoutes.Tnk.GetAll)]
- public async Task GetAll([FromQuery] PaginationQuery paginationQuery)
+ public async Task GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] TnkQuery filter)
{
var paginationFilter = mapper.Map(paginationQuery);
IQueryable query = tnkService.Get()
.OrderBy(t => t.Name);
+ if (filter.SubprocessId.HasValue)
+ query = query.Where(t => t.SubprocessId == filter.SubprocessId);
+
var tnks = await tnkService.GetPage(query, paginationFilter).ToListAsync();
if (!tnks.Any())
@@ -147,6 +115,42 @@ namespace PARR.API.Controllers.V1
}
+
+ ///
+ /// Создать ТНК
+ ///
+ ///
+ ///
+ [HttpPost(ApiRoutes.Tnk.Create)]
+ public async Task 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 { 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 { 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(mapper.Map(tnk), true));
+ }
+
+
///
/// Обновить ТНК
///
diff --git a/PARR.API/Controllers/V1/WorkController.cs b/PARR.API/Controllers/V1/WorkController.cs
index 5d781b9b..e8215898 100644
--- a/PARR.API/Controllers/V1/WorkController.cs
+++ b/PARR.API/Controllers/V1/WorkController.cs
@@ -68,6 +68,8 @@ namespace PARR.API.Controllers.V1
if (filter.Id.HasValue)
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();