Fix history

This commit is contained in:
s426226 2021-01-16 13:59:11 +01:00
parent 46b97ec42f
commit dd6a16df54
4 changed files with 25 additions and 5 deletions

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.DTO
{
public class UserHistoryDto
{
public List<string> History { get; set; }
public UserDto User { get; set; }
}
}

View File

@ -15,6 +15,7 @@ namespace Serwer.Infrastructure.Mappers
=> new MapperConfiguration(cfg => => new MapperConfiguration(cfg =>
{ {
cfg.CreateMap<User, UserDto>(); cfg.CreateMap<User, UserDto>();
cfg.CreateMap<UserHistory, UserHistoryDto>();
}) })
.CreateMapper(); .CreateMapper();
} }

View File

@ -1,5 +1,7 @@
using Serwer.Core.Domain; using AutoMapper;
using Serwer.Core.Domain;
using Serwer.Core.Repositories; using Serwer.Core.Repositories;
using Serwer.Infrastructure.DTO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,13 +14,15 @@ namespace Serwer.Infrastructure.Services
{ {
private readonly IHistoryRepository _historyRepository; private readonly IHistoryRepository _historyRepository;
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository) private readonly IMapper _mapper;
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository, IMapper mapper)
{ {
_historyRepository = historyRepository; _historyRepository = historyRepository;
_userRepository = userRepository; _userRepository = userRepository;
_mapper = mapper;
} }
public async Task<UserHistory> GetAsync(Guid userId) public async Task<UserHistoryDto> GetAsync(Guid userId)
{ {
var user = await _userRepository.GetAsync(userId); var user = await _userRepository.GetAsync(userId);
if(user == null) if(user == null)
@ -26,7 +30,7 @@ namespace Serwer.Infrastructure.Services
throw new Exception("Coś poszło nie tak."); throw new Exception("Coś poszło nie tak.");
} }
var history = await _historyRepository.GetAsync(user); var history = await _historyRepository.GetAsync(user);
return history; return _mapper.Map<UserHistoryDto>(history);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Serwer.Core.Domain; using Serwer.Core.Domain;
using Serwer.Infrastructure.DTO;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,6 +10,6 @@ namespace Serwer.Infrastructure.Services
{ {
public interface IHistoryService public interface IHistoryService
{ {
Task<UserHistory> GetAsync(Guid userId); Task<UserHistoryDto> GetAsync(Guid userId);
} }
} }