mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Creating the interface for where, sort & pages for the repository
This commit is contained in:
		
							parent
							
								
									b33acc5c2d
								
							
						
					
					
						commit
						e21f5d44a8
					
				@ -1,18 +1,56 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using JetBrains.Annotations;
 | 
					using JetBrains.Annotations;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Controllers
 | 
					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
 | 
						public interface IRepository<T> : IDisposable, IAsyncDisposable
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Task<T> Get(int id);
 | 
							Task<T> Get(int id);
 | 
				
			||||||
		Task<T> Get(string slug);
 | 
							Task<T> Get(string slug);
 | 
				
			||||||
		Task<ICollection<T>> Search(string query);
 | 
							Task<ICollection<T>> Search(string query);
 | 
				
			||||||
		Task<ICollection<T>> GetAll();
 | 
							
 | 
				
			||||||
 | 
							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<int> Create([NotNull] T obj);
 | 
							Task<int> Create([NotNull] T obj);
 | 
				
			||||||
		Task<int> CreateIfNotExists([NotNull] T obj);
 | 
							Task<int> CreateIfNotExists([NotNull] T obj);
 | 
				
			||||||
		Task Edit([NotNull] T edited, bool resetOld);
 | 
							Task Edit([NotNull] T edited, bool resetOld);
 | 
				
			||||||
 | 
				
			|||||||
@ -101,7 +101,7 @@ namespace Kyoo.Models
 | 
				
			|||||||
			if (EpisodeNumber >= episode.Season.Episodes.Count())
 | 
								if (EpisodeNumber >= episode.Season.Episodes.Count())
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				NextEpisode = episode.Show.Seasons
 | 
									NextEpisode = episode.Show.Seasons
 | 
				
			||||||
					.FirstOrDefault(x => x.SeasonNumber == SeasonNumber - 1)?.Episodes
 | 
										.FirstOrDefault(x => x.SeasonNumber == SeasonNumber + 1)?.Episodes
 | 
				
			||||||
					.FirstOrDefault(x => x.EpisodeNumber == 1);
 | 
										.FirstOrDefault(x => x.EpisodeNumber == 1);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ using System.Collections;
 | 
				
			|||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
using System.Reflection;
 | 
					using System.Reflection;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Text.RegularExpressions;
 | 
					using System.Text.RegularExpressions;
 | 
				
			||||||
@ -224,5 +225,16 @@ namespace Kyoo
 | 
				
			|||||||
				yield return ret;
 | 
									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,5 +1,6 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -363,7 +364,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return _shows.Delete(show);
 | 
								return _shows.Delete(show);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Task DeleteSeason(Season season)
 | 
							public Task DeleteSeason(Season season, IShowRepository repo)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return _seasons.Delete(season);
 | 
								return _seasons.Delete(season);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Linq.Expressions;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Kyoo.Models.Exceptions;
 | 
					using Kyoo.Models.Exceptions;
 | 
				
			||||||
@ -46,7 +47,9 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
				.ToListAsync();
 | 
									.ToListAsync();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public async Task<ICollection<Collection>> GetAll()
 | 
							public async Task<ICollection<Collection>> GetAll(Expression<Func<Collection, bool>> where = null, 
 | 
				
			||||||
 | 
								Sort<Collection> sort = default,
 | 
				
			||||||
 | 
								Pagination page = default)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return await _database.Collections.ToListAsync();
 | 
								return await _database.Collections.ToListAsync();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user