From d2de442b646048cb50b5450675e61dabcd5c570f Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 19 Apr 2021 21:19:20 +0200 Subject: [PATCH] Adding documentation to the IRepository interface --- Kyoo.Common/Controllers/IRepository.cs | 111 ++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/Kyoo.Common/Controllers/IRepository.cs b/Kyoo.Common/Controllers/IRepository.cs index bffe844e..4fa70691 100644 --- a/Kyoo.Common/Controllers/IRepository.cs +++ b/Kyoo.Common/Controllers/IRepository.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using JetBrains.Annotations; using Kyoo.Models; +using Kyoo.Models.Exceptions; namespace Kyoo.Controllers { @@ -111,44 +112,150 @@ namespace Kyoo.Controllers public interface IBaseRepository : IDisposable, IAsyncDisposable { /// - /// The type for witch this repository is responsible. + /// The type for witch this repository is responsible or null if non applicable. /// Type RepositoryType { get; } } + /// + /// A common repository for every resources. + /// It implement's and /. + /// + /// The resource's type that this repository manage. public interface IRepository : IBaseRepository where T : class, IResource { + /// + /// Get a resource from it's ID. + /// + /// The id of the resource + /// If the item could not be found. + /// The resource found Task Get(int id); + /// + /// Get a resource from it's slug. + /// + /// The slug of the resource + /// If the item could not be found. + /// The resource found Task Get(string slug); + /// + /// Get the first resource that match the predicate. + /// + /// A predicate to filter the resource. + /// If the item could not be found. + /// The resource found Task Get(Expression> where); + + /// + /// Search for resources. + /// + /// The query string. + /// A list of resources found Task> Search(string query); + /// + /// Get every resources that match all filters + /// + /// A filter predicate + /// Sort informations about the query (sort by, sort order) + /// How pagination should be done (where to start and how many to return) + /// A list of resources that match every filters Task> GetAll(Expression> where = null, Sort sort = default, Pagination limit = default); - + /// + /// Get every resources that match all filters + /// + /// A filter predicate + /// A sort by predicate. The order is ascending. + /// How pagination should be done (where to start and how many to return) + /// A list of resources that match every filters Task> GetAll([Optional] Expression> where, Expression> sort, Pagination limit = default ) => GetAll(where, new Sort(sort), limit); + /// + /// Get the number of resources that match the filter's predicate. + /// + /// A filter predicate + /// How many resources matched that filter Task GetCount(Expression> where = null); + /// + /// Create a new resource. + /// + /// The item to register + /// The resource registers and completed by database's informations (related items & so on) Task Create([NotNull] T obj); + + /// + /// Create a new resource if it does not exist already. If it does, the existing value is returned instead. + /// + /// The object to create + /// Allow issues to occurs in this method. Every issue is catched and ignored. + /// The newly created item or the existing value if it existed. Task CreateIfNotExists([NotNull] T obj, bool silentFail = false); + + /// + /// Edit a resource + /// + /// The resourcce to edit, it's ID can't change. + /// Should old properties of the resource be discarded or should null values considered as not changed? + /// The resource edited and completed by database's informations (related items & so on) Task Edit([NotNull] T edited, bool resetOld); + /// + /// Delete a resource by it's ID + /// + /// The ID of the resource Task Delete(int id); + /// + /// Delete a resource by it's slug + /// + /// The slug of the resource Task Delete(string slug); + /// + /// Delete a resource + /// + /// The resource to delete Task Delete([NotNull] T obj); + /// + /// Delete a list of resources. + /// + /// One or multiple resources to delete Task DeleteRange(params T[] objs) => DeleteRange(objs.AsEnumerable()); + /// + /// Delete a list of resources. + /// + /// An enumerable of resources to delete Task DeleteRange(IEnumerable objs); + /// + /// Delete a list of resources. + /// + /// One or multiple resources's id Task DeleteRange(params int[] ids) => DeleteRange(ids.AsEnumerable()); + /// + /// Delete a list of resources. + /// + /// An enumearble of resources's id Task DeleteRange(IEnumerable ids); + /// + /// Delete a list of resources. + /// + /// One or multiple resources's slug Task DeleteRange(params string[] slugs) => DeleteRange(slugs.AsEnumerable()); + /// + /// Delete a list of resources. + /// + /// An enumerable of resources's slug Task DeleteRange(IEnumerable slugs); + /// + /// Delete a list of resources. + /// + /// A predicate to filter resources to delete. Every resource that match this will be deleted. Task DeleteRange([NotNull] Expression> where); }