Changed method to return characters

This commit is contained in:
Karol Górzyński 2020-12-21 13:30:59 +01:00
parent 8de1b8bb5a
commit 0de41a2ce8
3 changed files with 10 additions and 13 deletions

View File

@ -10,7 +10,7 @@ namespace SessionCompanion.Services.Interfaces
{
public interface ICharacterService : IServiceBase<CharacterViewModel, Character>
{
Task<CharacterBasicStatsViewModel> GetBasicCharacterData(int characterId);
Task<IEnumerable<CharacterBasicStatsViewModel>> GetBasicCharactersData(List<int> charactersId);
Task<IEnumerable<CharacterForLoginViewModel>> GetUserLoginCharacters(int userId);
}
}

View File

@ -40,14 +40,14 @@ namespace SessionCompanion.Services.Services
/// <summary>
/// Funkcja zwraca podstawowy widok postaci na podstawie ich id
/// </summary>
/// <param name="characterId">identyfikator postaci</param>
/// <returns>Podstawowy widok danej postaci</returns>
public async Task<CharacterBasicStatsViewModel> GetBasicCharacterData(int characterId)
/// <param name="charactersId">Lista identyfikatorów postaci</param>
/// <returns>Podstawowy widok podanych postaci</returns>
public async Task<IEnumerable<CharacterBasicStatsViewModel>> GetBasicCharactersData(List<int> charactersId)
{
var characters = await Repository.Get(c => c.Id == characterId)
var characters = await Repository.Get(c => charactersId.Contains(c.Id))
.Include(x => x.Biography)
.Include(x => x.Statistics).ToListAsync();
var result = Mapper.Map<CharacterBasicStatsViewModel>(characters);
var result = Mapper.Map<IEnumerable<CharacterBasicStatsViewModel>>(characters);
return result;
}

View File

@ -71,13 +71,10 @@ namespace SessionCompanion.Controllers
[HttpGet("loggedCharacters")]
public async Task<Either<List<CharacterBasicStatsViewModel>, ErrorResponse>> GetLoggedUsersCharacters()
{
List<CharacterBasicStatsViewModel> characters = new List<CharacterBasicStatsViewModel>();
var connectedCharacters = _sessionHubData.ConnectedCharacters_Prop;
var characters = await _service.GetBasicCharactersData(connectedCharacters.Values.ToList());
foreach (var characterId in connectedCharacters.Values)
characters.Add(await _service.GetBasicCharacterData(characterId));
return characters;
return characters.ToList();
}
}
}