49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using Dapper;
|
|
using Galaeth.Core.Entities;
|
|
using Galaeth.Core.Infrastructure;
|
|
using Galaeth.Core.RepositoryInterfaces;
|
|
using Injectio.Attributes;
|
|
|
|
namespace Galaeth.DAL.Repositories;
|
|
|
|
/// <inheritdoc cref="Galaeth.Core.RepositoryInterfaces.IUserRepository" />
|
|
[RegisterScoped]
|
|
public class UserRepository : BaseRepository<User, Guid>, IUserRepository
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="UserRepository"/> class.
|
|
/// </summary>
|
|
/// <param name="db">Instance of <see cref="IDbConnectionProvider"/>.</param>
|
|
public UserRepository(IDbConnectionProvider db)
|
|
: base(db)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc cref="Galaeth.Core.RepositoryInterfaces.IUserRepository" />
|
|
public async Task<long> CountUsersAsync()
|
|
{
|
|
return await WithDatabaseAsync(async connection =>
|
|
await connection.QueryFirstAsync<long>($"SELECT COUNT(*) FROM {Table};"));
|
|
}
|
|
|
|
/// <inheritdoc cref="Galaeth.Core.RepositoryInterfaces.IUserRepository" />
|
|
public async Task<User> FindByUsername(string username)
|
|
{
|
|
return await WithDatabaseAsync(async connection =>
|
|
await connection.QueryFirstOrDefaultAsync<User>($"SELECT * FROM {Table} WHERE username = @pUsername", new
|
|
{
|
|
pUsername = username,
|
|
}));
|
|
}
|
|
|
|
/// <inheritdoc cref="Galaeth.Core.RepositoryInterfaces.IUserRepository" />
|
|
public async Task<User> FindByEmailAddress(string emailAddress)
|
|
{
|
|
return await WithDatabaseAsync(async connection =>
|
|
await connection.QueryFirstOrDefaultAsync<User>($"SELECT * FROM {Table} WHERE email = @pEmailAddress", new
|
|
{
|
|
pEmailAddress = emailAddress,
|
|
}));
|
|
}
|
|
}
|