Refactoring, database structure changed
This commit is contained in:
208
WatchIt.DTO/Models/Controllers/Media/MediaMappers.cs
Normal file
208
WatchIt.DTO/Models/Controllers/Media/MediaMappers.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using WatchIt.Database.Model.Media;
|
||||
using WatchIt.DTO.Models.Controllers.Genres;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Request;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
using WatchIt.DTO.Models.Generics.Image;
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
using WatchIt.DTO.Models.Generics.ViewCount;
|
||||
using MediumType = WatchIt.Database.Model.Media.MediumType;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media;
|
||||
|
||||
public static class MediaMappers
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
#region Medium
|
||||
|
||||
public static MediumMovie ToEntity(this MediumMovieRequest request)
|
||||
{
|
||||
MediumMovie medium = new MediumMovie();
|
||||
medium.UpdateWithRequest(request);
|
||||
return medium;
|
||||
}
|
||||
|
||||
public static void UpdateWithRequest(this MediumMovie entity, MediumMovieRequest request)
|
||||
{
|
||||
entity.SetMediumEntityProperties(request);
|
||||
entity.Budget = request.Budget;
|
||||
}
|
||||
|
||||
public static MediumSeries ToEntity(this MediumSeriesRequest request)
|
||||
{
|
||||
MediumSeries medium = new MediumSeries();
|
||||
medium.UpdateWithRequest(request);
|
||||
return medium;
|
||||
}
|
||||
|
||||
public static void UpdateWithRequest(this MediumSeries entity, MediumSeriesRequest request)
|
||||
{
|
||||
entity.SetMediumEntityProperties(request);
|
||||
entity.HasEnded = request.HasEnded;
|
||||
}
|
||||
|
||||
public static MediumResponse ToResponse(this Database.Model.Media.Medium entity)
|
||||
{
|
||||
MediumResponse response = new MediumResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.Type = entity.Type == MediumType.Movie ? Medium.Response.MediumResponseType.Movie : Medium.Response.MediumResponseType.Series;
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumMovieResponse ToResponse(this MediumMovie entity)
|
||||
{
|
||||
MediumMovieResponse response = new MediumMovieResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.SetMediumMovieResponseProperties(entity);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumSeriesResponse ToResponse(this MediumSeries entity)
|
||||
{
|
||||
MediumSeriesResponse response = new MediumSeriesResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.SetMediumSeriesResponseProperties(entity);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumUserRatedResponse ToResponse(this Database.Model.Media.Medium entity, long accountId)
|
||||
{
|
||||
MediumUserRatedResponse response = new MediumUserRatedResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.SetMediumUserRatedResponseProperties(entity, accountId);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumMovieUserRatedResponse ToResponse(this MediumMovie entity, long accountId)
|
||||
{
|
||||
MediumMovieUserRatedResponse response = new MediumMovieUserRatedResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.SetMediumMovieResponseProperties(entity);
|
||||
response.SetMediumUserRatedResponseProperties(entity, accountId);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumSeriesUserRatedResponse ToResponse(this MediumSeries entity, long accountId)
|
||||
{
|
||||
MediumSeriesUserRatedResponse response = new MediumSeriesUserRatedResponse();
|
||||
response.SetMediumResponseProperties(entity);
|
||||
response.SetMediumSeriesResponseProperties(entity);
|
||||
response.SetMediumUserRatedResponseProperties(entity, accountId);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static MediumRequest ToRequest(this BaseMediumResponse response)
|
||||
{
|
||||
MediumRequest request = response switch
|
||||
{
|
||||
MediumMovieResponse mediumMovieResponse => new MediumMovieRequest
|
||||
{
|
||||
Budget = mediumMovieResponse.Budget,
|
||||
},
|
||||
MediumSeriesResponse mediumSeriesResponse => new MediumSeriesRequest
|
||||
{
|
||||
HasEnded = mediumSeriesResponse.HasEnded,
|
||||
}
|
||||
};
|
||||
request.Title = response.Title;
|
||||
request.Description = response.Description;
|
||||
request.OriginalTitle = response.OriginalTitle;
|
||||
request.ReleaseDate = response.ReleaseDate;
|
||||
request.Duration = response.Duration;
|
||||
return request;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MediumPicture
|
||||
|
||||
public static MediumPicture ToEntity(this ImageRequest request, long mediumId) => new Database.Model.Media.MediumPicture
|
||||
{
|
||||
MediumId = mediumId,
|
||||
Image = request.Image,
|
||||
MimeType = request.MimeType,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region MediumGenre
|
||||
|
||||
public static MediumGenre CreateMediumGenre(long mediumId, short genreId) => new MediumGenre
|
||||
{
|
||||
MediumId = mediumId,
|
||||
GenreId = genreId,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region MediumRating
|
||||
|
||||
public static MediumRating ToEntity(this RatingRequest request, long mediumId, long userId)
|
||||
{
|
||||
MediumRating entity = new MediumRating
|
||||
{
|
||||
MediumId = mediumId,
|
||||
AccountId = userId
|
||||
};
|
||||
entity.UpdateWithRequest(request);
|
||||
return entity;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MediumViewCount
|
||||
|
||||
public static MediumViewCount CreateMediumViewCountEntity(long mediumId) => new MediumViewCount
|
||||
{
|
||||
MediumId = mediumId,
|
||||
ViewCount = 1,
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private static void SetMediumEntityProperties(this Database.Model.Media.Medium entity, MediumRequest request)
|
||||
{
|
||||
entity.Title = request.Title;
|
||||
entity.OriginalTitle = request.OriginalTitle;
|
||||
entity.Description = request.Description;
|
||||
entity.Duration = request.Duration;
|
||||
entity.ReleaseDate = request.ReleaseDate;
|
||||
}
|
||||
|
||||
private static void SetMediumResponseProperties(this BaseMediumResponse response, Database.Model.Media.Medium entity)
|
||||
{
|
||||
response.Id = entity.Id;
|
||||
response.Title = entity.Title;
|
||||
response.OriginalTitle = entity.OriginalTitle;
|
||||
response.Description = entity.Description;
|
||||
response.ReleaseDate = entity.ReleaseDate;
|
||||
response.Duration = entity.Duration;
|
||||
response.Genres = entity.Genres.Select(x => x.ToResponse());
|
||||
response.Rating = entity.Ratings.ToOverallResponse();
|
||||
response.ViewCount = entity.ViewCounts.ToResponse();
|
||||
response.Picture = entity.Picture?.ToResponse();
|
||||
}
|
||||
|
||||
private static void SetMediumMovieResponseProperties(this MediumMovieResponse response, MediumMovie entity)
|
||||
{
|
||||
response.Budget = entity.Budget;
|
||||
}
|
||||
|
||||
private static void SetMediumSeriesResponseProperties(this MediumSeriesResponse response, MediumSeries entity)
|
||||
{
|
||||
response.HasEnded = entity.HasEnded;
|
||||
}
|
||||
|
||||
private static void SetMediumUserRatedResponseProperties(this IMediumUserRatedResponse response, Database.Model.Media.Medium entity, long accountId)
|
||||
{
|
||||
response.RatingUser = entity.Ratings.SingleOrDefault(x => x.AccountId == accountId)?.ToUserResponse();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumDescriptionFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumDescriptionFilter(string? descriptionRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(descriptionRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.Description)
|
||||
&&
|
||||
Regex.IsMatch(x.Description, descriptionRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumGenresFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumGenresFilter(IEnumerable<short>? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
query.All(y => x.Genres.Select(z => z.Id).Contains(y))
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumMovieBudgetFromFilter : Filter<Database.Model.Media.MediumMovie>
|
||||
{
|
||||
public MediumMovieBudgetFromFilter(decimal? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.Budget >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumMovieBudgetToFilter : Filter<Database.Model.Media.MediumMovie>
|
||||
{
|
||||
public MediumMovieBudgetToFilter(decimal? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.Budget <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumOriginalTitleFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumOriginalTitleFilter(string? originalTitleRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(originalTitleRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.OriginalTitle)
|
||||
&&
|
||||
Regex.IsMatch(x.OriginalTitle, originalTitleRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingAverageFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingAverageFromFilter(decimal? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any()
|
||||
&&
|
||||
(decimal)x.Ratings.Average(y => y.Rating) >= query
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingAverageToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingAverageToFilter(decimal? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any()
|
||||
&&
|
||||
(decimal)x.Ratings.Average(y => y.Rating) <= query
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingCountFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingCountFromFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.Ratings.Count() >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingCountToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingCountToFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.Ratings.Count() <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingUserDateFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingUserDateFromFilter(DateOnly? query, long accountId) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any(x => x.AccountId == accountId)
|
||||
&&
|
||||
x.Ratings.First(x => x.AccountId == accountId).Date >= query.Value.ToDateTime(new TimeOnly(0, 0))
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingUserDateToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingUserDateToFilter(DateOnly? query, long accountId) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any(x => x.AccountId == accountId)
|
||||
&&
|
||||
x.Ratings.First(x => x.AccountId == accountId).Date <= query.Value.ToDateTime(new TimeOnly(23, 59))
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingUserRatingFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingUserRatingFromFilter(byte? query, long accountId) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any(x => x.AccountId == accountId)
|
||||
&&
|
||||
x.Ratings.First(x => x.AccountId == accountId).Rating >= query
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumRatingUserRatingToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumRatingUserRatingToFilter(byte? query, long accountId) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.Ratings.Any(x => x.AccountId == accountId)
|
||||
&&
|
||||
x.Ratings.First(x => x.AccountId == accountId).Rating <= query
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumReleaseDateFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumReleaseDateFromFilter(DateOnly? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.ReleaseDate.HasValue
|
||||
&&
|
||||
x.ReleaseDate.Value.CompareTo(query.Value) >= 0
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumReleaseDateToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumReleaseDateToFilter(DateOnly? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
(
|
||||
x.ReleaseDate.HasValue
|
||||
&&
|
||||
x.ReleaseDate.Value.CompareTo(query.Value) <= 0
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumSeriesHasEndedFilter : Filter<Database.Model.Media.MediumSeries>
|
||||
{
|
||||
public MediumSeriesHasEndedFilter(bool? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.HasEnded == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumTitleFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumTitleFilter(string? titleRegex) : base(x =>
|
||||
(
|
||||
string.IsNullOrWhiteSpace(titleRegex)
|
||||
||
|
||||
(
|
||||
!string.IsNullOrWhiteSpace(x.Title)
|
||||
&&
|
||||
Regex.IsMatch(x.Title, titleRegex, RegexOptions.IgnoreCase)
|
||||
)
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using WatchIt.Database.Model.Media;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumTypeFilter : Filter<Database.Model.Media.Medium>
|
||||
{
|
||||
public MediumTypeFilter(MediumType? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.Type == query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLast24HoursFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLast24HoursFromFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddDays(-1)))
|
||||
.Sum(y => y.ViewCount) >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLast24HoursToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLast24HoursToFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddDays(-1)))
|
||||
.Sum(y => y.ViewCount) <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastMonthFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastMonthFromFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)))
|
||||
.Sum(y => y.ViewCount) >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastMonthToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastMonthToFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)))
|
||||
.Sum(y => y.ViewCount) <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastWeekFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastWeekFromFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddDays(-7)))
|
||||
.Sum(y => y.ViewCount) >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastWeekToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastWeekToFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddDays(-7)))
|
||||
.Sum(y => y.ViewCount) <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastYearFromFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastYearFromFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddYears(-1)))
|
||||
.Sum(y => y.ViewCount) >= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
|
||||
public record MediumViewCountLastYearToFilter<T> : Filter<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
public MediumViewCountLastYearToFilter(long? query) : base(x =>
|
||||
(
|
||||
query == null
|
||||
||
|
||||
x.ViewCounts
|
||||
.Where(y => y.Date >= DateOnly.FromDateTime(DateTime.Now.AddYears(-1)))
|
||||
.Sum(y => y.ViewCount) <= query
|
||||
)) { }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Linq.Expressions;
|
||||
using WatchIt.Database.Model.Media;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium;
|
||||
|
||||
public static class MediumOrderKeys
|
||||
{
|
||||
public static Dictionary<string, Expression<Func<T, object?>>> Base<T>() where T : Database.Model.Media.Medium => new Dictionary<string, Expression<Func<T, object?>>>
|
||||
{
|
||||
{ "id", x => x.Id },
|
||||
{ "title", x => x.Title },
|
||||
{ "original_title", x => x.OriginalTitle },
|
||||
{ "description", x => x.Description },
|
||||
{ "release_date", x => x.ReleaseDate },
|
||||
{ "rating.average", x => x.Ratings.Any() ? x.Ratings.Average(y => y.Rating) : 0 },
|
||||
{ "rating.count", x => x.Ratings.Count() },
|
||||
{ "view_count.last_24_hours", x => x.ViewCounts.Where(y => y.Date.ToDateTime(new TimeOnly(23, 59)) >= DateTime.Now.AddDays(-1)).Sum(y => y.ViewCount) },
|
||||
{ "view_count.last_week", x => x.ViewCounts.Where(y => y.Date.ToDateTime(new TimeOnly(23, 59)) >= DateTime.Now.AddDays(-7)).Sum(y => y.ViewCount) },
|
||||
{ "view_count.last_month", x => x.ViewCounts.Where(y => y.Date.ToDateTime(new TimeOnly(23, 59)) >= DateTime.Now.AddMonths(-1)).Sum(y => y.ViewCount) },
|
||||
{ "view_count.last_year", x => x.ViewCounts.Where(y => y.Date.ToDateTime(new TimeOnly(23, 59)) >= DateTime.Now.AddYears(-1)).Sum(y => y.ViewCount) }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Expression<Func<Database.Model.Media.Medium, object?>>> Medium = new Dictionary<string, Expression<Func<Database.Model.Media.Medium, object?>>>
|
||||
{
|
||||
{ "type", x => x.Type },
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Expression<Func<MediumMovie, object?>>> MediumMovie = new Dictionary<string, Expression<Func<MediumMovie, object?>>>
|
||||
{
|
||||
{ "budget", x => x.Budget },
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Expression<Func<MediumSeries, object?>>> MediumSeries = new Dictionary<string, Expression<Func<MediumSeries, object?>>>
|
||||
{
|
||||
{ "has_ended", x => x.HasEnded },
|
||||
};
|
||||
|
||||
public static Dictionary<string, Expression<Func<T, object?>>> MediumUserRated<T>(long accountId) where T : Database.Model.Media.Medium => new Dictionary<string, Expression<Func<T, object?>>>
|
||||
{
|
||||
{ "rating_user.rating", x => x.Ratings.FirstOrDefault(x => x.AccountId == accountId) != null ? x.Ratings.FirstOrDefault(x => x.AccountId == accountId).Rating : null },
|
||||
{ "rating_user.date", x => x.Ratings.FirstOrDefault(x => x.AccountId == accountId) != null ? x.Ratings.FirstOrDefault(x => x.AccountId == accountId).Date : null },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Query;
|
||||
|
||||
public class BaseMediumFilterQuery<T> : IFilterQuery<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[FromQuery(Name = "original_title")]
|
||||
[AliasAs("original_title")]
|
||||
public string? OriginalTitle { get; set; }
|
||||
|
||||
[FromQuery(Name = "description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[FromQuery(Name = "release_date_from")]
|
||||
[AliasAs("release_date_from")]
|
||||
public DateOnly? ReleaseDateFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "release_date_to")]
|
||||
[AliasAs("release_date_to")]
|
||||
public DateOnly? ReleaseDateTo { get; set; }
|
||||
|
||||
[AliasAs("genre")]
|
||||
[FromQuery(Name = "genre")]
|
||||
public IEnumerable<short>? Genres { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_average_from")]
|
||||
[AliasAs("rating_average_from")]
|
||||
public decimal? RatingAverageFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_average_to")]
|
||||
[AliasAs("rating_average_to")]
|
||||
public decimal? RatingAverageTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_count_from")]
|
||||
[AliasAs("rating_count_from")]
|
||||
public long? RatingCountFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_count_to")]
|
||||
[AliasAs("rating_count_to")]
|
||||
public long? RatingCountTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_24_hours_from")]
|
||||
[AliasAs("view_count_last_24_hours_from")]
|
||||
public long? ViewCountLast24HoursFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_24_hours_from")]
|
||||
[AliasAs("view_count_last_24_hours_from")]
|
||||
public long? ViewCountLast24HoursTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_week_from")]
|
||||
[AliasAs("view_count_last_week_from")]
|
||||
public long? ViewCountLastWeekFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_week_to")]
|
||||
[AliasAs("view_count_last_week_to")]
|
||||
public long? ViewCountLastWeekTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_month_from")]
|
||||
[AliasAs("view_count_last_month_from")]
|
||||
public long? ViewCountLastMonthFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_month_to")]
|
||||
[AliasAs("view_count_last_month_to")]
|
||||
public long? ViewCountLastMonthTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_year_from")]
|
||||
[AliasAs("view_count_last_year_from")]
|
||||
public long? ViewCountLastYearFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "view_count_last_year_to")]
|
||||
[AliasAs("view_count_last_year_to")]
|
||||
public long? ViewCountLastYearTo { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public virtual IEnumerable<Filter<T>> GetFilters() =>
|
||||
[
|
||||
new MediumTitleFilter<T>(Title),
|
||||
new MediumOriginalTitleFilter<T>(OriginalTitle),
|
||||
new MediumDescriptionFilter<T>(Description),
|
||||
new MediumReleaseDateFromFilter<T>(ReleaseDateFrom),
|
||||
new MediumReleaseDateToFilter<T>(ReleaseDateTo),
|
||||
new MediumGenresFilter<T>(Genres),
|
||||
new MediumRatingAverageFromFilter<T>(RatingAverageFrom),
|
||||
new MediumRatingAverageToFilter<T>(RatingAverageTo),
|
||||
new MediumRatingCountFromFilter<T>(RatingCountFrom),
|
||||
new MediumRatingCountToFilter<T>(RatingCountTo),
|
||||
new MediumViewCountLast24HoursFromFilter<T>(ViewCountLast24HoursFrom),
|
||||
new MediumViewCountLast24HoursToFilter<T>(ViewCountLast24HoursTo),
|
||||
new MediumViewCountLastWeekFromFilter<T>(ViewCountLastWeekFrom),
|
||||
new MediumViewCountLastWeekToFilter<T>(ViewCountLastWeekTo),
|
||||
new MediumViewCountLastMonthFromFilter<T>(ViewCountLastMonthFrom),
|
||||
new MediumViewCountLastMonthToFilter<T>(ViewCountLastMonthTo),
|
||||
new MediumViewCountLastYearFromFilter<T>(ViewCountLastYearFrom),
|
||||
new MediumViewCountLastYearToFilter<T>(ViewCountLastYearTo),
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WatchIt.Database.Model.Media;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Query;
|
||||
|
||||
public class MediumFilterQuery : BaseMediumFilterQuery<Database.Model.Media.Medium>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "type")]
|
||||
public MediumType? Type { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override IEnumerable<Filter<Database.Model.Media.Medium>> GetFilters() => base.GetFilters()
|
||||
.Append(new MediumTypeFilter(Type));
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.Database.Model.Media;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Query;
|
||||
|
||||
public class MediumMovieFilterQuery : BaseMediumFilterQuery<MediumMovie>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "budget_from")]
|
||||
[AliasAs("budget_from")]
|
||||
public decimal? BudgetFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "budget_to")]
|
||||
[AliasAs("budget_to")]
|
||||
public decimal? BudgetTo { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override IEnumerable<Filter<MediumMovie>> GetFilters() => base.GetFilters()
|
||||
.Append(new MediumMovieBudgetFromFilter(BudgetFrom))
|
||||
.Append(new MediumMovieBudgetToFilter(BudgetTo));
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.Database.Model.Media;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Query;
|
||||
|
||||
public class MediumSeriesFilterQuery : BaseMediumFilterQuery<MediumSeries>
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "has_ended")]
|
||||
[AliasAs("has_ended")]
|
||||
public bool? HasEnded { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override IEnumerable<Filter<MediumSeries>> GetFilters() => base.GetFilters()
|
||||
.Append(new MediumSeriesHasEndedFilter(HasEnded));
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Filters;
|
||||
using WatchIt.DTO.Query;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Query;
|
||||
|
||||
public class MediumUserRatedFilterQuery<T> : IFilterQuery<T> where T : Database.Model.Media.Medium
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
[FromQuery(Name = "rating_user_rating_from")]
|
||||
[AliasAs("rating_user_rating_from")]
|
||||
public byte? RatingUserRatingFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_user_rating_to")]
|
||||
[AliasAs("rating_user_rating_to")]
|
||||
public byte? RatingUserRatingTo { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_user_date_from")]
|
||||
[AliasAs("rating_user_date_from")]
|
||||
public DateOnly? RatingUserDateFrom { get; set; }
|
||||
|
||||
[FromQuery(Name = "rating_user_date_to")]
|
||||
[AliasAs("rating_user_date_to")]
|
||||
public DateOnly? RatingUserDateTo { get; set; }
|
||||
|
||||
|
||||
[FromRoute(Name = "id")]
|
||||
public long AccountId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public IEnumerable<Filter<T>> GetFilters() =>
|
||||
[
|
||||
new MediumRatingUserRatingFromFilter<T>(RatingUserRatingFrom, AccountId),
|
||||
new MediumRatingUserRatingToFilter<T>(RatingUserRatingTo, AccountId),
|
||||
new MediumRatingUserDateFromFilter<T>(RatingUserDateFrom, AccountId),
|
||||
new MediumRatingUserDateToFilter<T>(RatingUserDateTo, AccountId)
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Request;
|
||||
|
||||
public class MediumMovieRequest : MediumRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public decimal? Budget { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Request;
|
||||
|
||||
public abstract class MediumRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public string Title { get; set; } = null!;
|
||||
public string? OriginalTitle { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
public short? Duration { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Request;
|
||||
|
||||
public class MediumSeriesRequest : MediumRequest
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public bool HasEnded { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using WatchIt.DTO.Models.Controllers.Genres.Genre;
|
||||
using WatchIt.DTO.Models.Generics.Image;
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
using WatchIt.DTO.Models.Generics.ViewCount;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public abstract class BaseMediumResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; } = null!;
|
||||
public string? OriginalTitle { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
public short? Duration { get; set; }
|
||||
public IEnumerable<GenreResponse> Genres { get; set; } = null!;
|
||||
public RatingOverallResponse Rating { get; set; } = null!;
|
||||
public ViewCountResponse ViewCount { get; set; } = null!;
|
||||
public ImageResponse? Picture { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public interface IMediumUserRatedResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
RatingUserResponse? RatingUser { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumMovieResponse : BaseMediumResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public decimal? Budget { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumMovieUserRatedResponse : MediumMovieResponse, IMediumUserRatedResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public RatingUserResponse? RatingUser { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumResponse : BaseMediumResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public MediumResponseType Type { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public enum MediumResponseType
|
||||
{
|
||||
Movie = 0,
|
||||
Series = 1,
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumSeriesResponse : BaseMediumResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public bool HasEnded { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumSeriesUserRatedResponse : MediumSeriesResponse, IMediumUserRatedResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public RatingUserResponse? RatingUser { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
|
||||
namespace WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
public class MediumUserRatedResponse : MediumResponse, IMediumUserRatedResponse
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public RatingUserResponse? RatingUser { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user