Poszukiwacz/Serwer/Serwer.Infrastructure/Services/HistoryService.cs
2021-01-16 13:59:11 +01:00

37 lines
1.1 KiB
C#

using AutoMapper;
using Serwer.Core.Domain;
using Serwer.Core.Repositories;
using Serwer.Infrastructure.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
public class HistoryService: IHistoryService
{
private readonly IHistoryRepository _historyRepository;
private readonly IUserRepository _userRepository;
private readonly IMapper _mapper;
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository, IMapper mapper)
{
_historyRepository = historyRepository;
_userRepository = userRepository;
_mapper = mapper;
}
public async Task<UserHistoryDto> GetAsync(Guid userId)
{
var user = await _userRepository.GetAsync(userId);
if(user == null)
{
throw new Exception("Coś poszło nie tak.");
}
var history = await _historyRepository.GetAsync(user);
return _mapper.Map<UserHistoryDto>(history);
}
}
}