测试
This commit is contained in:
30
MinimalAPI/Services/CategoryService.cs
Normal file
30
MinimalAPI/Services/CategoryService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user