Расширил контроллер для справок

1. Добавил контроллер, проверяющий наличие справки для страницы.
2. Добавил атрибут Required на некоторые параметры в методах в контроллере.
This commit is contained in:
parent 4778e98a16
commit 50a53fb1e4

View File

@ -21,12 +21,15 @@ public class HelpPageController : ControllerBase
{ {
private readonly IHelpPageService helpPageService; private readonly IHelpPageService helpPageService;
private readonly IUserRepository userRepository; private readonly IUserRepository userRepository;
private readonly IHelpPageRepository helpPageRepository;
public HelpPageController(IHelpPageService helpPageService, public HelpPageController(IHelpPageService helpPageService,
IUserRepository userRepository) IUserRepository userRepository,
IHelpPageRepository helpPageRepository)
{ {
this.helpPageService = helpPageService; this.helpPageService = helpPageService;
this.userRepository = userRepository; this.userRepository = userRepository;
this.helpPageRepository = helpPageRepository;
} }
/// <summary> /// <summary>
@ -41,7 +44,7 @@ public class HelpPageController : ControllerBase
[Permission] [Permission]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> UploadAsync( public async Task<IActionResult> UploadAsync(
string urlPage, [Required] string urlPage,
[Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")] [Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")]
int idCategory, int idCategory,
[Required] IFormFile file, [Required] IFormFile file,
@ -77,8 +80,10 @@ public class HelpPageController : ControllerBase
[Route("{urlPage}/{idCategory}")] [Route("{urlPage}/{idCategory}")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> GetFileAsync(string urlPage, public async Task<IActionResult> GetFileAsync(
int idCategory, [Required] string urlPage,
[Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")]
int idCategory,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var file = await helpPageService.GetFileStreamAsync(urlPage, var file = await helpPageService.GetFileStreamAsync(urlPage,
@ -94,4 +99,27 @@ public class HelpPageController : ControllerBase
return File(memoryStream, "application/pdf", file.fileName); return File(memoryStream, "application/pdf", file.fileName);
} }
/// <summary>
/// Проверяет наличие справки для страницы
/// </summary>
/// <param name="urlPage">Url страницы</param>
/// <param name="idCategory">Id категории файла. Допустимое значение параметра: 20000</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
[Route("isExisting/{urlPage}/{idCategory}")]
[ProducesResponseType(typeof(bool), (int)HttpStatusCode.OK)]
public async Task<IActionResult> 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);
}
} }