Refactoring, database structure changed

This commit is contained in:
2025-03-03 00:56:32 +01:00
Unverified
parent d3805ef3db
commit c603c41c0b
913 changed files with 21764 additions and 32775 deletions

View File

@@ -0,0 +1,8 @@
using System.Linq.Expressions;
namespace WatchIt.DTO.Query;
public abstract record Filter<T>(Expression<Func<T, bool>> Condition)
{
public static implicit operator Expression<Func<T, bool>>(Filter<T> filter) => filter.Condition;
}

View File

@@ -0,0 +1,20 @@
namespace WatchIt.DTO.Query;
public interface IFilterQuery;
public interface IFilterQuery<T> : IFilterQuery
{
internal abstract IEnumerable<Filter<T>> GetFilters();
}
public static class FilterQueryExtensions
{
public static IQueryable<T> ApplyFilter<T>(this IQueryable<T> data, IFilterQuery<T> filterQuery)
{
foreach (Filter<T> filter in filterQuery.GetFilters())
{
data = data.Where(filter);
}
return data;
}
}

View File

@@ -0,0 +1,38 @@
using System.Linq.Expressions;
using Microsoft.AspNetCore.Mvc;
using Refit;
using WatchIt.Database.Model.Media;
namespace WatchIt.DTO.Query;
public class OrderQuery
{
#region PROPERTIES
[FromQuery(Name = "order_asc")]
[AliasAs("order_asc")]
public bool OrderAscending { get; set; }
[FromQuery(Name = "order_by")]
[AliasAs("order_by")]
public string? OrderBy { get; set; }
#endregion
}
public static class OrderQueryExtensions
{
public static IQueryable<T> ApplyOrder<T>(this IQueryable<T> data, OrderQuery orderQuery, params IDictionary<string, Expression<Func<T, object?>>>[] orderKeys)
{
if (orderQuery.OrderBy is not null)
{
Dictionary<string, Expression<Func<T, object?>>> orderByKeys = orderKeys.SelectMany(x => x)
.ToDictionary(x => x.Key, x => x.Value);
if (orderByKeys.TryGetValue(orderQuery.OrderBy, out Expression<Func<T, object?>>? orderFunc))
{
data = orderQuery.OrderAscending ? data.OrderBy(orderFunc) : data.OrderByDescending(orderFunc);
}
}
return data;
}
}

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
namespace WatchIt.DTO.Query;
public sealed record PagingQuery
{
[FromQuery(Name = "first")]
public int? First { get; set; }
[FromQuery(Name = "after")]
public int? After { get; set; }
}
public static class PagingQueryExtensions
{
public static IQueryable<T> ApplyPaging<T>(this IQueryable<T> data, PagingQuery pagingQuery)
{
if (pagingQuery.After is not null)
{
data = data.Skip(pagingQuery.After.Value);
}
if (pagingQuery.First is not null)
{
data = data.Take(pagingQuery.First.Value);
}
return data;
}
}