mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Revert "Creating the interface for where, sort & pages for the repository"
This reverts commit a9ac47441be6e30067fe8587c27e0427110bcac1.
This commit is contained in:
parent
e21f5d44a8
commit
2f5b59afed
@ -1,56 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.Models;
|
||||
|
||||
namespace Kyoo.Controllers
|
||||
{
|
||||
public struct Pagination
|
||||
{
|
||||
public int Count;
|
||||
public int AfterID;
|
||||
}
|
||||
|
||||
public readonly struct Sort<T>
|
||||
{
|
||||
public string Key { get; }
|
||||
public bool Descendant { get; }
|
||||
|
||||
public Sort(string key, bool descendant = false)
|
||||
{
|
||||
Key = key;
|
||||
Descendant = descendant;
|
||||
}
|
||||
|
||||
public Sort(Expression<Func<T, object>> key)
|
||||
{
|
||||
Key = Utility.GetMemberName(key);
|
||||
Descendant = false;
|
||||
}
|
||||
|
||||
public static implicit operator Sort<T>([NotNull] Expression<Func<T, object>> key)
|
||||
{
|
||||
return new Sort<T>(Utility.GetMemberName(key));
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRepository<T> : IDisposable, IAsyncDisposable
|
||||
{
|
||||
Task<T> Get(int id);
|
||||
Task<T> Get(string slug);
|
||||
Task<ICollection<T>> Search(string query);
|
||||
|
||||
Task<ICollection<T>> GetAll(Expression<Func<T, bool>> where = null,
|
||||
Sort<T> sort = default,
|
||||
Pagination page = default);
|
||||
|
||||
Task<ICollection<T>> GetAll(Expression<Func<T, bool>> where = null,
|
||||
Expression<Func<T, object>> sort = default,
|
||||
Pagination page = default) => GetAll(where, new Sort<T>(sort), page);
|
||||
|
||||
Task<ICollection<T>> GetAll();
|
||||
Task<int> Create([NotNull] T obj);
|
||||
Task<int> CreateIfNotExists([NotNull] T obj);
|
||||
Task Edit([NotNull] T edited, bool resetOld);
|
||||
|
@ -101,7 +101,7 @@ namespace Kyoo.Models
|
||||
if (EpisodeNumber >= episode.Season.Episodes.Count())
|
||||
{
|
||||
NextEpisode = episode.Show.Seasons
|
||||
.FirstOrDefault(x => x.SeasonNumber == SeasonNumber + 1)?.Episodes
|
||||
.FirstOrDefault(x => x.SeasonNumber == SeasonNumber - 1)?.Episodes
|
||||
.FirstOrDefault(x => x.EpisodeNumber == 1);
|
||||
}
|
||||
else
|
||||
|
@ -3,7 +3,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -225,16 +224,5 @@ namespace Kyoo
|
||||
yield return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetMemberName<T>(Expression<Func<T, object>> key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
|
||||
if (!(key.Body is MemberExpression member))
|
||||
throw new ArgumentException("Key should be a member of the object.");
|
||||
|
||||
return member.Member.Name;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Models;
|
||||
|
||||
@ -364,7 +363,7 @@ namespace Kyoo.Controllers
|
||||
return _shows.Delete(show);
|
||||
}
|
||||
|
||||
public Task DeleteSeason(Season season, IShowRepository repo)
|
||||
public Task DeleteSeason(Season season)
|
||||
{
|
||||
return _seasons.Delete(season);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models.Exceptions;
|
||||
@ -47,9 +46,7 @@ namespace Kyoo.Controllers
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ICollection<Collection>> GetAll(Expression<Func<Collection, bool>> where = null,
|
||||
Sort<Collection> sort = default,
|
||||
Pagination page = default)
|
||||
public async Task<ICollection<Collection>> GetAll()
|
||||
{
|
||||
return await _database.Collections.ToListAsync();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user