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

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 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;
}
/// <summary>
@ -41,7 +44,7 @@ public class HelpPageController : ControllerBase
[Permission]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<IActionResult> 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<IActionResult> GetFileAsync(string urlPage,
int idCategory,
public async Task<IActionResult> 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);
}
/// <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);
}
}