From bd77db7b7883d194bfe2a334488ad4ed5e949986 Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Thu, 16 May 2024 11:58:56 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B0,=20?= =?UTF-8?q?=D1=82=D0=BD=D0=BA,=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=98=D0=94=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1/Requests/Queries/SubprocessQuery.cs | 10 +++ .../Contracts/V1/Requests/Queries/TnkQuery.cs | 10 +++ .../V1/Requests/Queries/WorkGetAllQuery.cs | 5 ++ .../Controllers/V1/SubprocessController.cs | 78 ++++++++++--------- PARR.API/Controllers/V1/TnkController.cs | 76 +++++++++--------- PARR.API/Controllers/V1/WorkController.cs | 2 + 6 files changed, 109 insertions(+), 72 deletions(-) create mode 100644 PARR.API/Contracts/V1/Requests/Queries/SubprocessQuery.cs create mode 100644 PARR.API/Contracts/V1/Requests/Queries/TnkQuery.cs 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();