Skip to content

Commit

Permalink
🔀 Merge pull request #15 from Fedodo/dev
Browse files Browse the repository at this point in the history
♻️ Updated to IEnumerable
  • Loading branch information
LNA-DEV authored Aug 9, 2023
2 parents 2929415 + 1bda765 commit 30fc2ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
6 changes: 1 addition & 5 deletions Fedodo.NuGet.Common/Interfaces/IMongoDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public Task<IEnumerable<T>> GetSpecificPaged<T>(string databaseName, string coll
public Task<IEnumerable<T>> GetAllPagedFromCollections<T>(string databaseName, string collectionName, int pageId,
int pageSize, SortDefinition<T> sortDefinition, string foreignCollectionName);

public Task<IEnumerable<T>> GetSpecificPagedFromCollections<T>(string databaseName, string collectionName,
int pageId, int pageSize, SortDefinition<T> sortDefinition, string foreignCollectionName,
FilterDefinition<T> filter);

public Task<long> CountSpecificFromCollections<T>(string databaseName, List<string> collectionNames,
public Task<long> CountSpecificFromCollections<T>(string databaseName, IEnumerable<string> collectionNames,
FilterDefinition<T> filter);

public Task<IEnumerable<T>> GetSpecificPagedFromCollections<T>(string databaseName,
Expand Down
29 changes: 3 additions & 26 deletions Fedodo.NuGet.Common/Repositories/MongoDbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,7 @@ public async Task<IEnumerable<T>> GetAllPagedFromCollections<T>(string databaseN

return result;
}

public async Task<IEnumerable<T>> GetSpecificPagedFromCollections<T>(string databaseName, string collectionName,
int pageId, int pageSize, SortDefinition<T> sortDefinition, string foreignCollectionName,
FilterDefinition<T> filter)
{
_logger.LogTrace($"Getting specific items paged of type: {typeof(T)}");

var database = _client.GetDatabase(databaseName);
var collection = database.GetCollection<T>(collectionName);
var foreignCollection = database.GetCollection<T>(foreignCollectionName);

var result = await collection.Aggregate()
.UnionWith(foreignCollection)
.Match(filter)
.Sort(sortDefinition)
.Skip(pageId * pageSize)
.Limit(pageSize)
.ToListAsync();

_logger.LogTrace($"Finished getting specific items paged of type: {typeof(T)}");

return result;
}


public async Task<IEnumerable<T>> GetSpecificPaged<T>(string databaseName, string collectionName, int pageId,
int pageSize,
SortDefinition<T> sortDefinition, FilterDefinition<T> filter)
Expand Down Expand Up @@ -187,13 +164,13 @@ public async Task<long> CountSpecific<T>(string databaseName, string collectionN
return result;
}

public async Task<long> CountSpecificFromCollections<T>(string databaseName, List<string> collectionNames,
public async Task<long> CountSpecificFromCollections<T>(string databaseName, IEnumerable<string> collectionNames,
FilterDefinition<T> filter)
{
_logger.LogTrace($"Counting all items of type: {typeof(T)} in {nameof(CountSpecificFromCollections)}");

var database = _client.GetDatabase(databaseName);
var collection = AggregateCollections<T>(collectionNames, database);
var collection = AggregateCollections<T>(collectionNames.ToList(), database);

var result = (await collection.Match(filter).Count().FirstOrDefaultAsync()).Count;

Expand Down

0 comments on commit 30fc2ca

Please sign in to comment.