Poszukiwacz/Serwer/Serwer.Infrastructure/Services/HistoryService.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2021-01-16 13:59:11 +01:00
using AutoMapper;
using Serwer.Core.Domain;
2021-01-09 14:44:14 +01:00
using Serwer.Core.Repositories;
2021-01-16 13:59:11 +01:00
using Serwer.Infrastructure.DTO;
2021-01-09 14:44:14 +01:00
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;
2021-01-16 13:59:11 +01:00
private readonly IMapper _mapper;
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository, IMapper mapper)
2021-01-09 14:44:14 +01:00
{
_historyRepository = historyRepository;
_userRepository = userRepository;
2021-01-16 13:59:11 +01:00
_mapper = mapper;
2021-01-09 14:44:14 +01:00
}
2021-01-16 13:59:11 +01:00
public async Task<UserHistoryDto> GetAsync(Guid userId)
2021-01-09 14:44:14 +01:00
{
var user = await _userRepository.GetAsync(userId);
if(user == null)
{
throw new Exception("Coś poszło nie tak.");
}
var history = await _historyRepository.GetAsync(user);
2021-01-16 13:59:11 +01:00
return _mapper.Map<UserHistoryDto>(history);
2021-01-09 14:44:14 +01:00
}
}
}