SES-105 list of logged charcters #36

Merged
s426134 merged 7 commits from SES-105 into dev 2020-12-21 13:40:47 +01:00
3 changed files with 10 additions and 13 deletions
Showing only changes of commit 0de41a2ce8 - Show all commits

View File

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

View File

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

View File

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

lepiej użyć metody .Contains od linq

lepiej użyć metody .Contains od linq
characters.Add(await _service.GetBasicCharacterData(characterId));
return characters;
} }
} }
} }