mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Start stored procs for user credentials
This commit is contained in:
@@ -4,10 +4,10 @@ namespace WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[ApiExplorerSettings(IgnoreApi = true)]
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
[Route("error")] // ← required
|
[Route("error")] // required
|
||||||
public class NotFoundController : ControllerBase
|
public class NotFoundController : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("404")] // ← required
|
[HttpGet("404")] //required
|
||||||
public IActionResult Handle404()
|
public IActionResult Handle404()
|
||||||
{
|
{
|
||||||
return NotFound(new { message = "Route not found." });
|
return NotFound(new { message = "Route not found." });
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using BusinessLayer.Services;
|
using BusinessLayer.Services;
|
||||||
using DataAccessLayer.Repositories;
|
using DataAccessLayer.Repositories;
|
||||||
|
using DataAccessLayer.Repositories.UserAccount;
|
||||||
using DataAccessLayer.Sql;
|
using DataAccessLayer.Sql;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
using DataAccessLayer.Entities;
|
|
||||||
|
|
||||||
namespace DataAccessLayer.Repositories
|
|
||||||
{
|
|
||||||
public interface IUserAccountRepository
|
|
||||||
{
|
|
||||||
Task Add(UserAccount userAccount);
|
|
||||||
Task<UserAccount?> GetById(Guid id);
|
|
||||||
Task<IEnumerable<UserAccount>> GetAll(int? limit, int? offset);
|
|
||||||
Task Update(UserAccount userAccount);
|
|
||||||
Task Delete(Guid id);
|
|
||||||
Task<UserAccount?> GetByUsername(string username);
|
|
||||||
Task<UserAccount?> GetByEmail(string email);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
using DataAccessLayer.Entities;
|
using System.Data;
|
||||||
using DataAccessLayer.Sql;
|
using DataAccessLayer.Sql;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace DataAccessLayer.Repositories
|
namespace DataAccessLayer.Repositories.UserAccount
|
||||||
{
|
{
|
||||||
public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
|
public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
|
||||||
: Repository<UserAccount>(connectionFactory), IUserAccountRepository
|
: Repository<Entities.UserAccount>(connectionFactory), IUserAccountRepository
|
||||||
{
|
{
|
||||||
public override async Task Add(UserAccount userAccount)
|
public override async Task Add(Entities.UserAccount userAccount)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_CreateUserAccount", connection);
|
await using var command = new SqlCommand("usp_CreateUserAccount", connection);
|
||||||
@@ -24,7 +23,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
await command.ExecuteNonQueryAsync();
|
await command.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<UserAccount?> GetById(Guid id)
|
public override async Task<Entities.UserAccount?> GetById(Guid id)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_GetUserAccountById", connection)
|
await using var command = new SqlCommand("usp_GetUserAccountById", connection)
|
||||||
@@ -38,7 +37,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IEnumerable<UserAccount>> GetAll(int? limit, int? offset)
|
public override async Task<IEnumerable<Entities.UserAccount>> GetAll(int? limit, int? offset)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_GetAllUserAccounts", connection);
|
await using var command = new SqlCommand("usp_GetAllUserAccounts", connection);
|
||||||
@@ -51,7 +50,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
command.Parameters.Add("@Offset", SqlDbType.Int).Value = offset.Value;
|
command.Parameters.Add("@Offset", SqlDbType.Int).Value = offset.Value;
|
||||||
|
|
||||||
await using var reader = await command.ExecuteReaderAsync();
|
await using var reader = await command.ExecuteReaderAsync();
|
||||||
var users = new List<UserAccount>();
|
var users = new List<Entities.UserAccount>();
|
||||||
|
|
||||||
while (await reader.ReadAsync())
|
while (await reader.ReadAsync())
|
||||||
{
|
{
|
||||||
@@ -61,7 +60,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Update(UserAccount userAccount)
|
public override async Task Update(Entities.UserAccount userAccount)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_UpdateUserAccount", connection);
|
await using var command = new SqlCommand("usp_UpdateUserAccount", connection);
|
||||||
@@ -87,7 +86,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
await command.ExecuteNonQueryAsync();
|
await command.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserAccount?> GetByUsername(string username)
|
public async Task<Entities.UserAccount?> GetByUsername(string username)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_GetUserAccountByUsername", connection);
|
await using var command = new SqlCommand("usp_GetUserAccountByUsername", connection);
|
||||||
@@ -99,7 +98,7 @@ namespace DataAccessLayer.Repositories
|
|||||||
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserAccount?> GetByEmail(string email)
|
public async Task<Entities.UserAccount?> GetByEmail(string email)
|
||||||
{
|
{
|
||||||
await using var connection = await CreateConnection();
|
await using var connection = await CreateConnection();
|
||||||
await using var command = new SqlCommand("usp_GetUserAccountByEmail", connection);
|
await using var command = new SqlCommand("usp_GetUserAccountByEmail", connection);
|
||||||
@@ -111,9 +110,9 @@ namespace DataAccessLayer.Repositories
|
|||||||
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
return await reader.ReadAsync() ? MapToEntity(reader) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override UserAccount MapToEntity(SqlDataReader reader)
|
protected override Entities.UserAccount MapToEntity(SqlDataReader reader)
|
||||||
{
|
{
|
||||||
return new UserAccount
|
return new Entities.UserAccount
|
||||||
{
|
{
|
||||||
UserAccountId = reader.GetGuid(reader.GetOrdinal("UserAccountId")),
|
UserAccountId = reader.GetGuid(reader.GetOrdinal("UserAccountId")),
|
||||||
Username = reader.GetString(reader.GetOrdinal("Username")),
|
Username = reader.GetString(reader.GetOrdinal("Username")),
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace DataAccessLayer.Repositories.UserCredential;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using DataAccessLayer;
|
using DataAccessLayer;
|
||||||
using DataAccessLayer.Entities;
|
using DataAccessLayer.Entities;
|
||||||
using DataAccessLayer.Repositories;
|
using DataAccessLayer.Repositories;
|
||||||
|
using DataAccessLayer.Repositories.UserAccount;
|
||||||
|
|
||||||
namespace DALTests
|
namespace DALTests
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using DataAccessLayer.Entities;
|
using DataAccessLayer.Entities;
|
||||||
using DataAccessLayer.Repositories;
|
using DataAccessLayer.Repositories;
|
||||||
|
using DataAccessLayer.Repositories.UserAccount;
|
||||||
|
|
||||||
namespace BusinessLayer.Services
|
namespace BusinessLayer.Services
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user