diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs index 58d1abe660..67a34041dc 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs @@ -132,4 +132,7 @@ public class Provider : IKeyedEntity, IImageDependentEntity public virtual List> Images { get; set; } public virtual ICollection ProviderSectionItems { get; set; } + + [NotMapped] + public static readonly ProviderStatus[] ValidProviderStatuses = { ProviderStatus.Approved, ProviderStatus.Recheck }; } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/FavoriteService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/FavoriteService.cs index b643fe439f..b193f552ee 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/FavoriteService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/FavoriteService.cs @@ -75,15 +75,17 @@ public async Task GetById(long id) /// public async Task> 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(x)).ToList(); + return favorites.Select(x => mapper.Map(x)); } ///