fix: update average rating information to be returned on seller endpoint for discover

This commit is contained in:
Damien Ostler 2024-02-11 01:38:13 -05:00
parent fe2aa82935
commit d5ae99872d
3 changed files with 6 additions and 1 deletions

View File

@ -38,6 +38,7 @@ public class DiscoveryController : Controller
public async Task<IActionResult> GetSeller(int sellerId)
{
var seller = await _dbContext.UserSellerProfiles
.Include(x=>x.SellerServices).ThenInclude(x=>x.Reviews)
.Include(x=>x.User)
.FirstOrDefaultAsync(x=>x.Id==sellerId);
if(seller==null)

View File

@ -7,4 +7,6 @@ public class DiscoverySellerModel
public List<string> SocialMediaLinks { get; set; }
public string Biography { get; set; }
public bool PrepaymentRequired { get; set; }
public double AverageRating { get; set; }
public int ReviewCount { get; set; }
}

View File

@ -23,7 +23,9 @@ public static class SellerProfileModelExtensions
Id = sellerProfile.Id,
SocialMediaLinks = sellerProfile.SocialMediaLinks,
Biography = sellerProfile.Biography,
PrepaymentRequired = sellerProfile.PrepaymentRequired
PrepaymentRequired = sellerProfile.PrepaymentRequired,
AverageRating = sellerProfile.SellerServices.Average(x=>x.Reviews.Average(y=>y.Rating)),
ReviewCount = sellerProfile.SellerServices.Sum(x=>x.Reviews.Count)
};
}
public static UserSellerProfile ToModel(this SellerProfileModel sellerProfile, UserSellerProfile existingSellerProfile)