Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix Rating #311

Merged
merged 3 commits into from
Sep 13, 2021
Merged

Bug fix Rating #311

merged 3 commits into from
Sep 13, 2021

Conversation

SergeyNovitsky
Copy link
Contributor

No description provided.

@SergeyNovitsky SergeyNovitsky changed the title Change method for adding information about user Bug fix Rating Sep 2, 2021
/// <returns>Tuple which contains part of user information (parentId, firstName and lastName.</returns>
public IEnumerable<(long parentId, string firstName, string lastName)> GetUsersByParents(IEnumerable<long> parentIds);
/// <returns>List of Parents.</returns>
public Task<IReadOnlyList<Parent>> GetParentsByIds(IEnumerable<long> parentIds);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetParentsByIdsAsync ?
or, since it is a parents repository: GetByIdsAsync ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -36,16 +36,13 @@ public new async Task<Parent> Create(Parent entity)
}

/// <inheritdoc/>
public IEnumerable<(long parentId, string firstName, string lastName)> GetUsersByParents(IEnumerable<long> parentIds)
public async Task<IReadOnlyList<Parent>> GetParentsByIds(IEnumerable<long> parentIds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a public method could you please apply argument checks here, like: null check and .Any().
It looks like we can also apply collection element uniqueness check here.

async -> await looks redundant here.
you can use expression body here:
=> db.Parents
.Where(parent => parentIds.Contains(parent.Id))
.ToListAsync();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added checks for null argument and if there any result. did not omit async await because of checks, and did not change to expression body too.

return GetUsersAsync(ratingsDto);
ratingsDto = await AddUserInformation(ratingsDto).ConfigureAwait(false);

return ratingsDto;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant assignment, you can return AddUserInformation(ratingsDto) without awaiting the result here.

@@ -99,7 +101,9 @@ public async Task<IEnumerable<RatingDto>> GetAllByEntityId(long entityId, Rating

var ratingsDto = ratings.Select(r => r.ToModel());

return GetUsersAsync(ratingsDto);
ratingsDto = await AddUserInformation(ratingsDto).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we want to save result into ratingsDto instead of just return the result ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -348,17 +354,17 @@ private async Task<bool> EntityExists(long id, RatingType type)
}
}

private IEnumerable<RatingDto> GetUsersAsync(IEnumerable<RatingDto> ratingDtos)
private async Task<IEnumerable<RatingDto>> AddUserInformation(IEnumerable<RatingDto> ratingDtos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddParentInfoAsync ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
var ratingDtosList = ratingDtos.ToList();

var newUsers = parentRepository.GetUsersByParents(ratingDtosList.Select(r => r.ParentId).Distinct());
var parents = await parentRepository.GetParentsByIds(ratingDtos.Select(rating => rating.ParentId).Distinct()).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract local variable with parent ids.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

{
var ratingDtosList = ratingDtos.ToList();

var newUsers = parentRepository.GetUsersByParents(ratingDtosList.Select(r => r.ParentId).Distinct());
var parents = await parentRepository.GetParentsByIds(ratingDtos.Select(rating => rating.ParentId).Distinct()).ConfigureAwait(false);

for (int i = 0; i < ratingDtosList.Count; i++)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use ratingDtoList.ForEach(...) to update elements inside the collection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to Select for do not cast IEnumerable to List here.

@SergeyNovitsky SergeyNovitsky force-pushed the novitsky/bug_fix_Ratings branch from 8d7b995 to 054bcc3 Compare September 13, 2021 06:52
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 19 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@SergeyNovitsky SergeyNovitsky merged commit 2152c34 into develop Sep 13, 2021
@DmyMi DmyMi deleted the novitsky/bug_fix_Ratings branch February 10, 2022 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants