Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CategoriesController.cs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Diligent.WebAPI.Contracts.DTOs.Categories;
  2. using Microsoft.AspNetCore.Mvc;
  3. namespace Diligent.WebAPI.Host.Controllers.V1
  4. {
  5. [ApiVersion("1.0")]
  6. [Route("v{version:apiVersion}/categories")]
  7. [ApiController]
  8. public class CategoriesController : ControllerBase
  9. {
  10. private readonly ICategoryService _categoryService;
  11. public CategoriesController(ICategoryService categoryService)
  12. {
  13. _categoryService = categoryService;
  14. }
  15. [HttpGet("root-categories/{parentCategoryId:int?}")]
  16. public async Task<IActionResult> GetRootCategories(int parentCategoryId = -1)
  17. {
  18. User? user = (User?)HttpContext.Items["User"];
  19. return Ok(await _categoryService.GetRootCategories(user.Id, parentCategoryId));
  20. }
  21. [HttpGet("granted-categories")]
  22. public async Task<IActionResult> GetCategories(int userId) =>
  23. Ok(await _categoryService.GetCategories(userId));
  24. [HttpGet("all-categories")]
  25. public async Task<IActionResult> GetAllCategories() =>
  26. Ok(await _categoryService.GetAllCategories());
  27. [HttpPost]
  28. public async Task<IActionResult> CreateCategory([FromBody] CreateCategoryDto request)
  29. {
  30. await _categoryService.CreateAsync(request);
  31. return StatusCode((int)HttpStatusCode.Created);
  32. }
  33. }
  34. }