getandupdate and getpaginated

This commit is contained in:
Sean Garrett
2023-07-06 19:15:10 +01:00
parent 3a7b24262e
commit 67784e64ee
2 changed files with 77 additions and 43 deletions
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
@@ -25,11 +26,13 @@ namespace MongoDbGenericRepository
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument>(
Expression<Func<TDocument, bool>> filter,
int skipNumber = 0,
int takeNumber = 50,
string partitionKey = null)
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument;
/// <summary>
@@ -41,11 +44,13 @@ namespace MongoDbGenericRepository
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
int skipNumber = 0,
int takeNumber = 50,
string partitionKey = null)
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
@@ -63,6 +68,22 @@ namespace MongoDbGenericRepository
FindOneAndUpdateOptions<TDocument, TDocument> options)
where TDocument : IDocument;
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<TDocument> GetAndUpdateOne<TDocument>(
FilterDefinition<TDocument> filter,
UpdateDefinition<TDocument> update,
FindOneAndUpdateOptions<TDocument, TDocument> options,
CancellationToken cancellationToken)
where TDocument : IDocument;
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
@@ -78,5 +99,23 @@ namespace MongoDbGenericRepository
FindOneAndUpdateOptions<TDocument, TDocument> options)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<TDocument> GetAndUpdateOne<TDocument, TKey>(
FilterDefinition<TDocument> filter,
UpdateDefinition<TDocument> update,
FindOneAndUpdateOptions<TDocument, TDocument> options,
CancellationToken cancellationToken)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
}
}