fix: fixes SonarQube issues

This commit is contained in:
Jean Gatto
2024-05-16 09:40:17 -03:00
parent f16d5ac751
commit 4e6b0be9a0
4 changed files with 19 additions and 12 deletions
-2
View File
@@ -1,5 +1,3 @@
version: '3.9'
services:
shop-webapi:
-2
View File
@@ -1,5 +1,3 @@
version: '3.9'
networks:
app-network:
driver: bridge
@@ -25,6 +25,9 @@ internal abstract class BaseReadOnlyRepository<TQueryModel, Tkey>(IReadDbContext
/// </summary>
/// <param name="id">The id of the query model.</param>
/// <returns>The query model.</returns>
public async Task<TQueryModel> GetByIdAsync(Tkey id) =>
await Collection.Find(queryModel => queryModel.Id.Equals(id)).FirstOrDefaultAsync();
public async Task<TQueryModel> GetByIdAsync(Tkey id)
{
using var asyncCursor = await Collection.FindAsync(queryModel => queryModel.Id.Equals(id));
return await asyncCursor.FirstOrDefaultAsync();
}
}
@@ -11,10 +11,18 @@ namespace Shop.Query.Data.Repositories;
internal class CustomerReadOnlyRepository(IReadDbContext readDbContext)
: BaseReadOnlyRepository<CustomerQueryModel, Guid>(readDbContext), ICustomerReadOnlyRepository
{
public async Task<IEnumerable<CustomerQueryModel>> GetAllAsync() =>
await Collection
.Find(Builders<CustomerQueryModel>.Filter.Empty)
.SortBy(customer => customer.FirstName)
.ThenBy(customer => customer.DateOfBirth)
.ToListAsync();
public async Task<IEnumerable<CustomerQueryModel>> GetAllAsync()
{
var sort = Builders<CustomerQueryModel>.Sort
.Ascending(customer => customer.FirstName)
.Descending(customer => customer.DateOfBirth);
var findOptions = new FindOptions<CustomerQueryModel>
{
Sort = sort
};
using var asyncCursor = await Collection.FindAsync(Builders<CustomerQueryModel>.Filter.Empty, findOptions);
return await asyncCursor.ToListAsync();
}
}