Files
it/MinimalAPI/Services/CategoryService.cs

30 lines
983 B
C#
Raw Normal View History

2025-11-03 17:03:57 +08:00
using AutoMapper;
using HardwarePerformance.Models.DTOs;
using HardwarePerformance.Repositories;
namespace HardwarePerformance.Services
{
public class CategoryService : ICategoryService
{
private readonly ICategoryRepository _categoryRepository;
private readonly IMapper _mapper;
public CategoryService(ICategoryRepository categoryRepository, IMapper mapper)
{
_categoryRepository = categoryRepository;
_mapper = mapper;
}
public async Task<IEnumerable<CategoryDto>> GetAllCategoriesAsync()
{
var categories = await _categoryRepository.GetAllAsync();
return _mapper.Map<IEnumerable<CategoryDto>>(categories);
}
public async Task<CategoryDto?> GetCategoryByIdAsync(int id)
{
var category = await _categoryRepository.GetByIdAsync(id);
return category != null ? _mapper.Map<CategoryDto>(category) : null;
}
}
}