Working on the UserRepository functionality

+ Tests
+ QueryableExtensions. It is an add-on that allows you to implement exceptions if the returned List would be empty.
This commit is contained in:
Artemy
2025-06-17 13:11:56 +07:00
parent 568b09ba81
commit 694750e25d
7 changed files with 147 additions and 21 deletions
+4
View File
@@ -10,4 +10,8 @@
<Folder Include="DTOs\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
namespace Govor.Core.Infrastructure.Extensions;
public static class QueryableExtensions
{
public static async Task<List<T>> ToListOrThrowIfEmpty<T>(this IQueryable<T> query, Exception ex)
{
var list = await query.ToListAsync();
if (list.Count == 0) throw ex;
return list;
}
}
+4 -5
View File
@@ -6,9 +6,8 @@ public interface IUsersReader
{
public Task<IEnumerable<User>> GetAll();
public Task<User> FindById(Guid id);
public Task<IEnumerable<User>> FindByRangeId(IEnumerable<Guid> ids);
public Task<User> FindByUsername(string username);
public Task<IEnumerable<User>> FindByRangeUsername(IEnumerable<string> usernames);
public Task<IEnumerable<User>> FindUsersByCreatedDate(DateOnly createdDate);
public Task<List<User>> FindByRangeId(IEnumerable<Guid> ids);
public Task<List<User>> FindUsersByName(string username);
public Task<List<User>> FindByRangeUsername(IEnumerable<string> usernames);
public Task<List<User>> FindUsersByCreatedDate(DateOnly createdDate);
}