Refactoring, database structure changed
This commit is contained in:
30
WatchIt.DTO/Models/Generics/ViewCount/ViewCountMappers.cs
Normal file
30
WatchIt.DTO/Models/Generics/ViewCount/ViewCountMappers.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using WatchIt.Database.Model;
|
||||
|
||||
namespace WatchIt.DTO.Models.Generics.ViewCount;
|
||||
|
||||
public static class ViewCountMappers
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public static ViewCountResponse ToResponse(this IEnumerable<IViewCountEntity> viewCounts)
|
||||
{
|
||||
IEnumerable<IViewCountEntity> viewCountEntities = viewCounts.ToList();
|
||||
return new ViewCountResponse
|
||||
{
|
||||
Last24Hours = viewCountEntities.CountFrom(DateTime.Now.AddDays(-1)),
|
||||
LastWeek = viewCountEntities.CountFrom(DateTime.Now.AddDays(-7)),
|
||||
LastMonth = viewCountEntities.CountFrom(DateTime.Now.AddMonths(-1)),
|
||||
LastYear = viewCountEntities.CountFrom(DateTime.Now.AddYears(-1)),
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private static long CountFrom(this IEnumerable<IViewCountEntity> viewCounts, DateTime date) => viewCounts.Where(x => x.Date >= DateOnly.FromDateTime(date)).Sum(x => x.ViewCount);
|
||||
|
||||
#endregion
|
||||
}
|
||||
13
WatchIt.DTO/Models/Generics/ViewCount/ViewCountResponse.cs
Normal file
13
WatchIt.DTO/Models/Generics/ViewCount/ViewCountResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace WatchIt.DTO.Models.Generics.ViewCount;
|
||||
|
||||
public class ViewCountResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public long Last24Hours { get; set; }
|
||||
public long LastWeek { get; set; }
|
||||
public long LastMonth { get; set; }
|
||||
public long LastYear { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user