Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VladyslavPavlysko committed Jun 26, 2024
1 parent c019d36 commit 7057089
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,33 @@ public async Task<Result<IEnumerable<StreetcodeMainPageDTO>>> Handle(GetPageOfSt
descendingSortKeySelector: sc => sc.CreatedAt)
.Entities;

if (streetcodes != null)
if (streetcodes is not null && streetcodes.Any())
{
const int keyNumOfImageToDisplay = (int)ImageAssigment.Blackandwhite;
foreach (var streetcode in streetcodes)
{
streetcode.Images = streetcode.Images.Where(x => x.ImageDetails != null && x.ImageDetails.Alt.Equals(keyNumOfImageToDisplay.ToString())).ToList();
}

var shuffledStreetcodes = new List<StreetcodeContent>();

using (var rng = RandomNumberGenerator.Create())
{
shuffledStreetcodes = streetcodes.OrderBy(sc =>
{
byte[] random = new byte[4];
rng.GetBytes(random);
return BitConverter.ToInt32(random, 0) & 0x7FFFFFFF;
}).ToList();
}

return Result.Ok(_mapper.Map<IEnumerable<StreetcodeMainPageDTO>>(shuffledStreetcodes));
return Result.Ok(_mapper.Map<IEnumerable<StreetcodeMainPageDTO>>(ShuffleStreetcodes(streetcodes)));
}

string errorMsg = _stringLocalizerNo["NoStreetcodesExistNow"].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(errorMsg);
}

private static List<StreetcodeContent> ShuffleStreetcodes(IEnumerable<StreetcodeContent> streetcodes)
{
using (var rng = RandomNumberGenerator.Create())
{
return streetcodes.OrderBy(sc =>
{
byte[] random = new byte[4];
rng.GetBytes(random);
return BitConverter.ToInt32(random, 0) & 0x7FFFFFFF;
}).ToList();
}
}
}
}

0 comments on commit 7057089

Please sign in to comment.