From c8ec264f137879f45d08d82e9510df95956e4be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 12 Jul 2023 18:16:36 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Добавил новый метод в контроллер. 2. В репозитории сделал проверку на наличие справки для страницы. 3. В методах контроллера добавил фильтрацию для id категории. --- .../Repositories/IHelpPageRepository.cs | 11 ++++++++ .../Repository/HelpPageRepository.cs | 5 ++++ .../Controllers/HelpPageController.cs | 28 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/AsbCloudApp/Repositories/IHelpPageRepository.cs b/AsbCloudApp/Repositories/IHelpPageRepository.cs index 26f9c69e..4864d2cf 100644 --- a/AsbCloudApp/Repositories/IHelpPageRepository.cs +++ b/AsbCloudApp/Repositories/IHelpPageRepository.cs @@ -20,4 +20,15 @@ public interface IHelpPageRepository : ICrudRepository Task GetOrDefaultByUrlPageAndIdCategoryAsync(string urlPage, int idCategory, CancellationToken cancellationToken); + + /// + /// Проверяет наличие справки для страницы + /// + /// + /// + /// + /// + Task IsExistingAsync(string urlPage, + int idCategory, + CancellationToken cancellationToken); } diff --git a/AsbCloudInfrastructure/Repository/HelpPageRepository.cs b/AsbCloudInfrastructure/Repository/HelpPageRepository.cs index dfc912a3..bf1cbbf3 100644 --- a/AsbCloudInfrastructure/Repository/HelpPageRepository.cs +++ b/AsbCloudInfrastructure/Repository/HelpPageRepository.cs @@ -31,4 +31,9 @@ public class HelpPageRepository : CrudRepositoryBase, return helpPage.Adapt(); } + + public Task IsExistingAsync(string urlPage, int idCategory, CancellationToken cancellationToken) => + dbContext.HelpPages.AnyAsync(h => h.UrlPage == urlPage && + h.IdCategory == idCategory, + cancellationToken); } diff --git a/AsbCloudWebApi/Controllers/HelpPageController.cs b/AsbCloudWebApi/Controllers/HelpPageController.cs index bae2010e..26d4ec4b 100644 --- a/AsbCloudWebApi/Controllers/HelpPageController.cs +++ b/AsbCloudWebApi/Controllers/HelpPageController.cs @@ -21,12 +21,15 @@ public class HelpPageController : ControllerBase { private readonly IHelpPageService helpPageService; private readonly IUserRepository userRepository; + private readonly IHelpPageRepository helpPageRepository; public HelpPageController(IHelpPageService helpPageService, - IUserRepository userRepository) + IUserRepository userRepository, + IHelpPageRepository helpPageRepository) { this.helpPageService = helpPageService; this.userRepository = userRepository; + this.helpPageRepository = helpPageRepository; } /// @@ -78,7 +81,8 @@ public class HelpPageController : ControllerBase [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task GetFileAsync(string urlPage, - int idCategory, + [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] + int idCategory, CancellationToken cancellationToken) { var file = await helpPageService.GetFileStreamAsync(urlPage, @@ -94,4 +98,24 @@ public class HelpPageController : ControllerBase return File(memoryStream, "application/pdf", file.fileName); } + + /// + /// Проверяет наличие справки для страницы + /// + /// Url страницы + /// Id категории файла. Допустимое значение параметра: 20000 + /// + /// + [HttpGet] + [Route("isExisting/{urlPage}/{idCategory}")] + [ProducesResponseType(typeof(bool), (int)HttpStatusCode.OK)] + public async Task IsExistingAsync(string urlPage, + [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] + int idCategory, + CancellationToken cancellationToken) + { + return Ok(await helpPageRepository.IsExistingAsync(urlPage, + idCategory, + cancellationToken)); + } }