| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using Diligent.WebAPI.Contracts.DTOs.Categories;
- using Microsoft.AspNetCore.Mvc;
-
- namespace Diligent.WebAPI.Host.Controllers.V1
- {
- [ApiVersion("1.0")]
- [Route("v{version:apiVersion}/categories")]
- [ApiController]
- public class CategoriesController : ControllerBase
- {
- private readonly ICategoryService _categoryService;
-
- public CategoriesController(ICategoryService categoryService)
- {
- _categoryService = categoryService;
- }
-
- [HttpGet("root-categories/{parentCategoryId:int?}")]
- public async Task<IActionResult> GetRootCategories(int parentCategoryId = -1)
- {
- User? user = (User?)HttpContext.Items["User"];
- return Ok(await _categoryService.GetRootCategories(user.Id, parentCategoryId));
- }
-
- [HttpGet("granted-categories")]
- public async Task<IActionResult> GetCategories(int userId) =>
- Ok(await _categoryService.GetCategories(userId));
-
- [HttpGet("all-categories")]
- public async Task<IActionResult> GetAllCategories()
- {
- User? user = (User?)HttpContext.Items["User"];
- return Ok(await _categoryService.GetAllCategories(user.Id));
- }
-
- [HttpPost]
- public async Task<IActionResult> CreateCategory([FromBody] CreateCategoryDto request)
- {
- User? user = (User?)HttpContext.Items["User"];
- await _categoryService.CreateAsync(request, user.Id);
- return StatusCode((int)HttpStatusCode.Created);
- }
- }
- }
|