Rated people panel added
This commit is contained in:
@@ -25,35 +25,11 @@ public class RatingResponse
|
||||
public RatingResponse() {}
|
||||
|
||||
[SetsRequiredMembers]
|
||||
private RatingResponse(long ratingSum, long ratingCount)
|
||||
internal RatingResponse(long ratingSum, long ratingCount)
|
||||
{
|
||||
Average = ratingCount > 0 ? (decimal)ratingSum / ratingCount : 0;
|
||||
Count = ratingCount;
|
||||
}
|
||||
|
||||
public static RatingResponse Create(long ratingSum, long ratingCount) => new RatingResponse(ratingSum, ratingCount);
|
||||
|
||||
public static RatingResponse Create(IEnumerable<RatingMedia> ratingMedia) => Create(ratingMedia, x => x.Rating);
|
||||
|
||||
public static RatingResponse Create(IEnumerable<RatingPersonActorRole> ratingPersonActorRoles) => Create(ratingPersonActorRoles, x => x.Rating);
|
||||
|
||||
public static RatingResponse Create(IEnumerable<RatingPersonCreatorRole> ratingPersonCreatorRoles) => Create(ratingPersonCreatorRoles, x => x.Rating);
|
||||
|
||||
public static RatingResponse Create<T>(IEnumerable<T> ratingList, Func<T, short> ratingSelector) => new RatingResponse(ratingList.Sum(x => ratingSelector(x)), ratingList.Count());
|
||||
|
||||
public static RatingResponse Create(IEnumerable<PersonActorRole> personActorRoles, IEnumerable<PersonCreatorRole> personCreatorRoles)
|
||||
{
|
||||
IEnumerable<RatingPersonActorRole> ratingsActorRoles = personActorRoles.SelectMany(x => x.RatingPersonActorRole);
|
||||
IEnumerable<RatingPersonCreatorRole> ratingsCreatorRoles = personCreatorRoles.SelectMany(x => x.RatingPersonCreatorRole);
|
||||
return Create(ratingsActorRoles, ratingsCreatorRoles);
|
||||
}
|
||||
|
||||
public static RatingResponse Create(IEnumerable<RatingPersonActorRole> ratingsActorRoles, IEnumerable<RatingPersonCreatorRole> ratingsCreatorRoles)
|
||||
{
|
||||
long ratingSum = ratingsActorRoles.Sum(x => x.Rating) + ratingsCreatorRoles.Sum(x => x.Rating);
|
||||
long ratingCount = ratingsActorRoles.Count() + ratingsCreatorRoles.Count();
|
||||
return new RatingResponse(ratingSum, ratingCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace WatchIt.Common.Model.Rating;
|
||||
|
||||
public class RatingResponseBuilder
|
||||
{
|
||||
#region FIELDS
|
||||
|
||||
private long _sum;
|
||||
private long _count;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
private RatingResponseBuilder() { }
|
||||
|
||||
public static RatingResponseBuilder Initialize() => new RatingResponseBuilder();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public RatingResponseBuilder Add<T>(IEnumerable<T> collection, Func<T, short> selector)
|
||||
{
|
||||
_sum += collection.Sum(x => selector(x));
|
||||
_count += collection.Count();
|
||||
return this;
|
||||
}
|
||||
public RatingResponse Build() => new RatingResponse(_sum, _count);
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user