mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Refactor repository methods to async and update credential logic
This commit is contained in:
@@ -13,11 +13,11 @@ namespace DataAccessLayer.Repositories
|
||||
return connection;
|
||||
}
|
||||
|
||||
public abstract Task Add(T entity);
|
||||
public abstract Task<IEnumerable<T>> GetAll(int? limit, int? offset);
|
||||
public abstract Task<T?> GetById(Guid id);
|
||||
public abstract Task Update(T entity);
|
||||
public abstract Task Delete(Guid id);
|
||||
public abstract Task AddAsync(T entity);
|
||||
public abstract Task<IEnumerable<T>> GetAllAsync(int? limit, int? offset);
|
||||
public abstract Task<T?> GetByIdAsync(Guid id);
|
||||
public abstract Task UpdateAsync(T entity);
|
||||
public abstract Task DeleteAsync(Guid id);
|
||||
|
||||
protected abstract T MapToEntity(SqlDataReader reader);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
{
|
||||
public interface IUserAccountRepository
|
||||
{
|
||||
Task Add(Entities.UserAccount userAccount);
|
||||
Task<Entities.UserAccount?> GetById(Guid id);
|
||||
Task<IEnumerable<Entities.UserAccount>> GetAll(int? limit, int? offset);
|
||||
Task Update(Entities.UserAccount userAccount);
|
||||
Task Delete(Guid id);
|
||||
Task<Entities.UserAccount?> GetByUsername(string username);
|
||||
Task<Entities.UserAccount?> GetByEmail(string email);
|
||||
Task AddAsync(Entities.UserAccount userAccount);
|
||||
Task<Entities.UserAccount?> GetByIdAsync(Guid id);
|
||||
Task<IEnumerable<Entities.UserAccount>> GetAllAsync(int? limit, int? offset);
|
||||
Task UpdateAsync(Entities.UserAccount userAccount);
|
||||
Task DeleteAsync(Guid id);
|
||||
Task<Entities.UserAccount?> GetByUsernameAsync(string username);
|
||||
Task<Entities.UserAccount?> GetByEmailAsync(string email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
|
||||
: Repository<Entities.UserAccount>(connectionFactory), IUserAccountRepository
|
||||
{
|
||||
public override async Task Add(Entities.UserAccount userAccount)
|
||||
public override async Task AddAsync(Entities.UserAccount userAccount)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_CreateUserAccount", connection);
|
||||
@@ -23,7 +23,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public override async Task<Entities.UserAccount?> GetById(Guid id)
|
||||
public override async Task<Entities.UserAccount?> GetByIdAsync(Guid id)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_GetUserAccountById", connection)
|
||||
@@ -37,7 +37,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<Entities.UserAccount>> GetAll(int? limit, int? offset)
|
||||
public override async Task<IEnumerable<Entities.UserAccount>> GetAllAsync(int? limit, int? offset)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_GetAllUserAccounts", connection);
|
||||
@@ -60,7 +60,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
return users;
|
||||
}
|
||||
|
||||
public override async Task Update(Entities.UserAccount userAccount)
|
||||
public override async Task UpdateAsync(Entities.UserAccount userAccount)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_UpdateUserAccount", connection);
|
||||
@@ -76,7 +76,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public override async Task Delete(Guid id)
|
||||
public override async Task DeleteAsync(Guid id)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_DeleteUserAccount", connection);
|
||||
@@ -86,7 +86,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public async Task<Entities.UserAccount?> GetByUsername(string username)
|
||||
public async Task<Entities.UserAccount?> GetByUsernameAsync(string username)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_GetUserAccountByUsername", connection);
|
||||
@@ -98,7 +98,7 @@ namespace DataAccessLayer.Repositories.UserAccount
|
||||
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
||||
}
|
||||
|
||||
public async Task<Entities.UserAccount?> GetByEmail(string email)
|
||||
public async Task<Entities.UserAccount?> GetByEmailAsync(string email)
|
||||
{
|
||||
await using var connection = await CreateConnection();
|
||||
await using var command = new SqlCommand("usp_GetUserAccountByEmail", connection);
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
namespace DataAccessLayer.Repositories.UserCredential;
|
||||
using DataAccessLayer.Entities;
|
||||
|
||||
public interface IUserCredentialRepository
|
||||
{
|
||||
Task Add(Entities.UserCredential credential);
|
||||
Task<Entities.UserCredential?> GetById(Guid userCredentialId);
|
||||
Task<Entities.UserCredential?> GetByUserAccountId(Guid userAccountId);
|
||||
Task<IEnumerable<Entities.UserCredential>> GetAll(int? limit, int? offset);
|
||||
Task Update(Entities.UserCredential credential);
|
||||
Task Delete(Guid userCredentialId);
|
||||
}
|
||||
Task RotateCredentialAsync(Guid userAccountId, UserCredential credential);
|
||||
Task<UserCredential?> GetActiveCredentialByUserAccountIdAsync(Guid userAccountId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user