diff options
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Data')
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs | 39 | ||||
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj | 4 |
2 files changed, 37 insertions, 6 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs b/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs index dc23bf4..ea8d8cb 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs +++ b/lib/VNLib.Plugins.Extensions.Data/src/ProtectedEntityExtensions.cs @@ -25,10 +25,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Collections.Generic; using VNLib.Utils; using VNLib.Plugins.Extensions.Data.Abstractions; + namespace VNLib.Plugins.Extensions.Data { public static class ProtectedEntityExtensions @@ -40,7 +42,7 @@ namespace VNLib.Plugins.Extensions.Data /// <param name="record">The record to update</param> /// <param name="userId">The userid of the record owner</param> /// <returns>A task that evaluates to the number of records modified</returns> - public static Task<ERRNO> UpdateAsync<TEntity>(this IDataStore<TEntity> store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task<ERRNO> UpdateUserRecordAsync<TEntity>(this IDataStore<TEntity> store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity { record.UserId = userId; return store.UpdateAsync(record); @@ -53,7 +55,7 @@ namespace VNLib.Plugins.Extensions.Data /// <param name="record">The record to update</param> /// <param name="userId">The userid of the record owner</param> /// <returns>A task that evaluates to the number of records modified</returns> - public static Task<ERRNO> CreateAsync<TEntity>(this IDataStore<TEntity> store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task<ERRNO> CreateUserRecordAsync<TEntity>(this IDataStore<TEntity> store, TEntity record, string userId) where TEntity : class, IDbModel, IUserEntity { record.UserId = userId; return store.CreateAsync(record); @@ -66,21 +68,50 @@ namespace VNLib.Plugins.Extensions.Data /// <param name="key">The unique id of the entity</param> /// <param name="userId">The user's id that owns the resource</param> /// <returns>A task that resolves the entity or null if not found</returns> - public static Task<TEntity?> GetSingleAsync<TEntity>(this IDataStore<TEntity> store, string key, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task<TEntity?> GetSingleUserRecordAsync<TEntity>(this IDataStore<TEntity> store, string key, string userId) where TEntity : class, IDbModel, IUserEntity { return store.GetSingleAsync(key, userId); } /// <summary> + /// Gets a page by its number offset constrained by its limit, + /// for the given user id + /// </summary> + /// <typeparam name="TEntity"></typeparam> + /// <param name="store"></param> + /// <param name="collection">The collection to store found records</param> + /// <param name="userId">The user to get the page for</param> + /// <param name="page">The page offset</param> + /// <param name="limit">The record limit for the page</param> + /// <returns>A task that resolves the number of entities added to the collection</returns> + public static Task<int> GetUserPageAsync<TEntity>(this IPaginatedDataStore<TEntity> store, ICollection<TEntity> collection, string userId, int page, int limit) + where TEntity : class, IDbModel, IUserEntity + { + return store.GetPageAsync(collection, page, limit, userId); + } + + /// <summary> /// Deletes a single entiry by its ID only if it belongs to the speicifed user /// </summary> /// <param name="store"></param> /// <param name="key">The unique id of the entity</param> /// <param name="userId">The user's id that owns the resource</param> /// <returns>A task the resolves the number of eneities deleted (should evaluate to true or false)</returns> - public static Task<ERRNO> DeleteAsync<TEntity>(this IDataStore<TEntity> store, string key, string userId) where TEntity : class, IDbModel, IUserEntity + public static Task<ERRNO> DeleteUserRecordAsync<TEntity>(this IDataStore<TEntity> store, string key, string userId) where TEntity : class, IDbModel, IUserEntity { return store.DeleteAsync(key, userId); } + + /// <summary> + /// Gets the record count for the specified userId + /// </summary> + /// <typeparam name="TEntity"></typeparam> + /// <param name="store"></param> + /// <param name="userId">The unique id of the user to query record count</param> + /// <returns>A task that resolves the number of records belonging to the specified user</returns> + public static Task<long> GetUserRecordCountAsync<TEntity>(this IDataStore<TEntity> store, string userId) where TEntity : class, IDbModel, IUserEntity + { + return store.GetCountAsync(userId); + } } } diff --git a/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj b/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj index bf09e6d..67310b6 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj +++ b/lib/VNLib.Plugins.Extensions.Data/src/VNLib.Plugins.Extensions.Data.csproj @@ -37,8 +37,8 @@ <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> - <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" /> - <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.11" /> + <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.13" /> </ItemGroup> <ItemGroup> |