Explorar el Código

get all categories

BE_dev
Dzenis Hadzifejzovic hace 3 años
padre
commit
20fe510297

+ 1
- 0
Diligent.WebAPI.Business/MappingProfiles/CategoryMappingProfile.cs Ver fichero

#endregion #endregion


#region Model to DTO #region Model to DTO
CreateMap<Category, TreeCategoryItem>();
#endregion #endregion
} }
} }

+ 6
- 0
Diligent.WebAPI.Business/Services/CategoryService.cs Ver fichero



return dto; return dto;
} }

public async Task<List<TreeCategoryItem>> GetAllCategories()
{
var res = await _context.Categories.Include(k => k.ParentCategory).ToListAsync();
return _mapper.Map<List<TreeCategoryItem>>(res);
}
} }
} }

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/ICategoryService.cs Ver fichero

Task<CategoriesParentChild> GetRootCategories(int userId,int categoryId); Task<CategoriesParentChild> GetRootCategories(int userId,int categoryId);
Task<Category> GetCategoryEntityById(int? id); Task<Category> GetCategoryEntityById(int? id);
Task<List<IsGrantedCategory>> GetCategories(int userId); Task<List<IsGrantedCategory>> GetCategories(int userId);
Task<List<TreeCategoryItem>> GetAllCategories();
} }
} }

+ 16
- 0
Diligent.WebAPI.Contracts/DTOs/Categories/TreeCategoryItem.cs Ver fichero

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;
}
}

+ 4
- 0
Diligent.WebAPI.Host/Controllers/V1/CategoriesController.cs Ver fichero

[HttpGet("granted-categories")] [HttpGet("granted-categories")]
public async Task<IActionResult> GetCategories(int userId) => public async Task<IActionResult> GetCategories(int userId) =>
Ok(await _categoryService.GetCategories(userId)); Ok(await _categoryService.GetCategories(userId));

[HttpGet("all-categories")]
public async Task<IActionResult> GetAllCategories() =>
Ok(await _categoryService.GetAllCategories());
} }
} }

Cargando…
Cancelar
Guardar