From 50a53fb1e45b638f53ba91ab2db46ddcb4e59065 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: Fri, 14 Jul 2023 12:39:02 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Добавил контроллер, проверяющий наличие справки для страницы. 2. Добавил атрибут Required на некоторые параметры в методах в контроллере. --- .../Controllers/HelpPageController.cs | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/AsbCloudWebApi/Controllers/HelpPageController.cs b/AsbCloudWebApi/Controllers/HelpPageController.cs index bae2010e..b230557b 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; } /// @@ -41,7 +44,7 @@ public class HelpPageController : ControllerBase [Permission] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] public async Task UploadAsync( - string urlPage, + [Required] string urlPage, [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] int idCategory, [Required] IFormFile file, @@ -77,8 +80,10 @@ public class HelpPageController : ControllerBase [Route("{urlPage}/{idCategory}")] [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK)] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task GetFileAsync(string urlPage, - int idCategory, + public async Task GetFileAsync( + [Required] string urlPage, + [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] + int idCategory, CancellationToken cancellationToken) { var file = await helpPageService.GetFileStreamAsync(urlPage, @@ -94,4 +99,27 @@ 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( + [Required] string urlPage, + [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] + int idCategory, + CancellationToken cancellationToken) + { + var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(urlPage, + idCategory, + cancellationToken); + + return Ok(helpPage != null); + } }