Refactor user registration process to use UserRegistrationDto;

implement user registration in seed app
This commit is contained in:
Aaron Po
2026-08-04 05:12:18 -04:00
parent d469c07250
commit c9a02dbedf
10 changed files with 186 additions and 144 deletions

View File

@@ -38,12 +38,12 @@ public class RegisterUserHandler(
string hashed = passwordInfrastructure.Hash(request.Password);
UserAccount createdUser = await authRepo.RegisterUserAsync(
request.Username,
new UserRegistrationDto(request.Username,
request.FirstName,
request.LastName,
request.Email,
request.DateOfBirth,
hashed
hashed)
);
string accessToken = tokenService.GenerateAccessToken(createdUser);

View File

@@ -0,0 +1,10 @@
namespace Features.Auth.Dtos;
public record UserRegistrationDto(
string Username,
string FirstName,
string LastName,
string Email,
DateTime DateOfBirth,
string PasswordHash
);

View File

@@ -1,6 +1,7 @@
using System.Data;
using System.Data.Common;
using Domain.Entities;
using Features.Auth.Dtos;
using Infrastructure.Sql;
using Microsoft.Data.SqlClient;
@@ -35,12 +36,7 @@ public class AuthRepository(ISqlConnectionFactory connectionFactory)
/// <exception cref="Exception">Thrown when the newly registered user cannot be retrieved after registration.</exception>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
public async Task<UserAccount> RegisterUserAsync(
string username,
string firstName,
string lastName,
string email,
DateTime dateOfBirth,
string passwordHash
UserRegistrationDto userRegistrationDto
)
{
await using DbConnection connection = await CreateConnection();
@@ -49,6 +45,9 @@ public class AuthRepository(ISqlConnectionFactory connectionFactory)
command.CommandText = "USP_RegisterUser";
command.CommandType = CommandType.StoredProcedure;
var (username, firstName, lastName, email, dateOfBirth, passwordHash) =
userRegistrationDto;
AddParameter(command, "@Username", username);
AddParameter(command, "@FirstName", firstName);
AddParameter(command, "@LastName", lastName);

View File

@@ -1,7 +1,7 @@
using Domain.Entities;
using Features.Auth.Dtos;
namespace Features.Auth.Repository;
/// <summary>
/// Repository for authentication-related database operations including user registration and credential management.
/// </summary>
@@ -11,20 +11,8 @@ public interface IAuthRepository
/// Registers a new user with account details and initial credential.
/// Uses stored procedure: USP_RegisterUser
/// </summary>
/// <param name="username">Unique username for the user</param>
/// <param name="firstName">User's first name</param>
/// <param name="lastName">User's last name</param>
/// <param name="email">User's email address</param>
/// <param name="dateOfBirth">User's date of birth</param>
/// <param name="passwordHash">Hashed password</param>
/// <returns>The newly created UserAccount with generated ID</returns>
Task<UserAccount> RegisterUserAsync(
string username,
string firstName,
string lastName,
string email,
DateTime dateOfBirth,
string passwordHash
UserRegistrationDto userRegistrationDto
);
/// <summary>