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); + } }