| @@ -18,6 +18,7 @@ namespace Diligent.WebAPI.Business.MappingProfiles | |||
| #endregion | |||
| #region Model to DTO | |||
| CreateMap<Category, TreeCategoryItem>(); | |||
| #endregion | |||
| } | |||
| } | |||
| @@ -148,5 +148,11 @@ namespace Diligent.WebAPI.Business.Services | |||
| return dto; | |||
| } | |||
| public async Task<List<TreeCategoryItem>> GetAllCategories() | |||
| { | |||
| var res = await _context.Categories.Include(k => k.ParentCategory).ToListAsync(); | |||
| return _mapper.Map<List<TreeCategoryItem>>(res); | |||
| } | |||
| } | |||
| } | |||
| @@ -12,5 +12,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| Task<CategoriesParentChild> GetRootCategories(int userId,int categoryId); | |||
| Task<Category> GetCategoryEntityById(int? id); | |||
| Task<List<IsGrantedCategory>> GetCategories(int userId); | |||
| Task<List<TreeCategoryItem>> GetAllCategories(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| using System.Threading.Tasks; | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Categories | |||
| { | |||
| public class TreeCategoryItem | |||
| { | |||
| public int Id { get; set; } | |||
| public string Name { get; set; } | |||
| public TreeCategoryItem? ParentCategory { get; set; } = null; | |||
| } | |||
| } | |||
| @@ -24,5 +24,9 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| [HttpGet("granted-categories")] | |||
| public async Task<IActionResult> GetCategories(int userId) => | |||
| Ok(await _categoryService.GetCategories(userId)); | |||
| [HttpGet("all-categories")] | |||
| public async Task<IActionResult> GetAllCategories() => | |||
| Ok(await _categoryService.GetAllCategories()); | |||
| } | |||
| } | |||