using Dapper;
using Galaeth.Core.Entities;
using Galaeth.Core.Infrastructure;
using Galaeth.Core.RepositoryInterfaces;
using Injectio.Attributes;
namespace Galaeth.DAL.Repositories;
///
[RegisterScoped]
public class UserRepository : BaseRepository, IUserRepository
{
///
/// Initializes a new instance of the class.
///
/// Instance of .
public UserRepository(IDbConnectionProvider db)
: base(db)
{
}
///
public async Task CountUsersAsync()
{
return await WithDatabaseAsync(async connection =>
await connection.QueryFirstAsync($"SELECT COUNT(*) FROM {Table};"));
}
///
public async Task FindByUsername(string username)
{
return await WithDatabaseAsync(async connection =>
await connection.QueryFirstOrDefaultAsync($"SELECT * FROM {Table} WHERE username = @pUsername", new
{
pUsername = username,
}));
}
///
public async Task FindByEmailAddress(string emailAddress)
{
return await WithDatabaseAsync(async connection =>
await connection.QueryFirstOrDefaultAsync($"SELECT * FROM {Table} WHERE email = @pEmailAddress", new
{
pEmailAddress = emailAddress,
}));
}
}