This commit is contained in:
Damien Ostler 2024-02-11 01:47:58 -05:00
parent 078488969e
commit 23890f294e
2 changed files with 14 additions and 4 deletions

View File

@ -29,7 +29,7 @@ public class DiscoveryController : Controller
.Where(x=>x.User.DisplayName.Contains(search)) .Where(x=>x.User.DisplayName.Contains(search))
.Include(x=>x.User) .Include(x=>x.User)
.Skip(offset).Take(pageSize).ToListAsync(); .Skip(offset).Take(pageSize).ToListAsync();
var result = sellers.Select(x=>x.ToDiscoveryModel()).ToList(); var result = sellers.Select(x=>x.ToDiscoveryModelWithoutReviews()).ToList();
return Ok(result); return Ok(result);
} }

View File

@ -15,9 +15,8 @@ public static class SellerProfileModelExtensions
PrepaymentRequired = sellerProfile.PrepaymentRequired PrepaymentRequired = sellerProfile.PrepaymentRequired
}; };
} }
public static DiscoverySellerModel ToDiscoveryModel(this UserSellerProfile sellerProfile) public static DiscoverySellerModel ToDiscoveryModelWithoutReviews(this UserSellerProfile sellerProfile)
{ {
return new DiscoverySellerModel() return new DiscoverySellerModel()
{ {
Name = sellerProfile.User.DisplayName, Name = sellerProfile.User.DisplayName,
@ -25,7 +24,18 @@ public static class SellerProfileModelExtensions
SocialMediaLinks = sellerProfile.SocialMediaLinks, SocialMediaLinks = sellerProfile.SocialMediaLinks,
Biography = sellerProfile.Biography, Biography = sellerProfile.Biography,
PrepaymentRequired = sellerProfile.PrepaymentRequired, PrepaymentRequired = sellerProfile.PrepaymentRequired,
AverageRating = sellerProfile.SellerServices?.Average(x=>x.Reviews.Average(y=>y.Rating)), };
}
public static DiscoverySellerModel ToDiscoveryModel(this UserSellerProfile sellerProfile)
{
return new DiscoverySellerModel()
{
Name = sellerProfile.User.DisplayName,
Id = sellerProfile.Id,
SocialMediaLinks = sellerProfile.SocialMediaLinks,
Biography = sellerProfile.Biography,
PrepaymentRequired = sellerProfile.PrepaymentRequired,
AverageRating = sellerProfile.SellerServices?.Average(x=>x.Reviews?.Average(y=>y.Rating)),
ReviewCount = sellerProfile.SellerServices?.Sum(x=>x.Reviews.Count) ReviewCount = sellerProfile.SellerServices?.Sum(x=>x.Reviews.Count)
}; };
} }