forked from ddrilling/AsbCloudServer
Добавил новый метод контроллера
1. Добавил новый метод в контроллер. 2. В репозитории сделал проверку на наличие справки для страницы. 3. В методах контроллера добавил фильтрацию для id категории.
This commit is contained in:
parent
5ae54386ad
commit
c8ec264f13
@ -20,4 +20,15 @@ public interface IHelpPageRepository : ICrudRepository<HelpPageDto>
|
|||||||
Task<HelpPageDto?> GetOrDefaultByUrlPageAndIdCategoryAsync(string urlPage,
|
Task<HelpPageDto?> GetOrDefaultByUrlPageAndIdCategoryAsync(string urlPage,
|
||||||
int idCategory,
|
int idCategory,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проверяет наличие справки для страницы
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="urlPage"></param>
|
||||||
|
/// <param name="idCategory"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> IsExistingAsync(string urlPage,
|
||||||
|
int idCategory,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
|
@ -31,4 +31,9 @@ public class HelpPageRepository : CrudRepositoryBase<HelpPageDto, HelpPage>,
|
|||||||
|
|
||||||
return helpPage.Adapt<HelpPageDto>();
|
return helpPage.Adapt<HelpPageDto>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<bool> IsExistingAsync(string urlPage, int idCategory, CancellationToken cancellationToken) =>
|
||||||
|
dbContext.HelpPages.AnyAsync(h => h.UrlPage == urlPage &&
|
||||||
|
h.IdCategory == idCategory,
|
||||||
|
cancellationToken);
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
@ -78,7 +81,8 @@ public class HelpPageController : ControllerBase
|
|||||||
[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(string urlPage,
|
||||||
int idCategory,
|
[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 +98,24 @@ 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(string urlPage,
|
||||||
|
[Range(minimum: 20000, maximum: 20000, ErrorMessage = "Категория файла недопустима. Допустимые: 20000")]
|
||||||
|
int idCategory,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Ok(await helpPageRepository.IsExistingAsync(urlPage,
|
||||||
|
idCategory,
|
||||||
|
cancellationToken));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user