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

Fix Get method for Favorites #1029

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ public class Provider : IKeyedEntity<Guid>, IImageDependentEntity<Provider>
public virtual List<Image<Provider>> Images { get; set; }

public virtual ICollection<ProviderSectionItem> ProviderSectionItems { get; set; }

[NotMapped]
public static readonly ProviderStatus[] ValidProviderStatuses = { ProviderStatus.Approved, ProviderStatus.Recheck };
}
14 changes: 8 additions & 6 deletions OutOfSchool/OutOfSchool.WebApi/Services/FavoriteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ public async Task<FavoriteDto> GetById(long id)
/// <inheritdoc/>
public async Task<IEnumerable<FavoriteDto>> GetAllByUser(string userId)
{
logger.LogInformation($"Getting Favorites by User started. Looking UserId = {userId}.");
logger.LogInformation("Getting Favorites by User started. Looking UserId = {UserId}", userId);

var favorites = await favoriteRepository.GetByFilter(x => x.UserId == userId && x.Workshop.Provider.Status == ProviderStatus.Approved).ConfigureAwait(false);
var favoritesQuery = await favoriteRepository.GetByFilter(x => x.UserId == userId && Provider.ValidProviderStatuses.Contains(x.Workshop.Provider.Status)).ConfigureAwait(false);
var favorites = favoritesQuery.ToList();

logger.LogInformation(!favorites.Any()
? $"There aren't Favorites for User with Id = {userId}."
: $"All {favorites.Count()} records were successfully received from the Favorites table");
logger.LogInformation(
"All {Count} records were successfully received from the Favorites table for User with Id = {UserId}",
favorites.Count,
userId);

return favorites.Select(x => mapper.Map<FavoriteDto>(x)).ToList();
return favorites.Select(x => mapper.Map<FavoriteDto>(x));
}

/// <inheritdoc/>
Expand Down