Format ./web/backend/Features/Features.UserManagement

This commit is contained in:
Aaron Po
2026-06-20 15:09:43 -04:00
parent e2e5eb89e3
commit b298bd02d3
11 changed files with 33 additions and 44 deletions

View File

@@ -7,14 +7,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/> <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Domain\Domain.Entities\Domain.Entities.csproj"/> <ProjectReference Include="..\..\Domain\Domain.Entities\Domain.Entities.csproj" />
<ProjectReference Include="..\..\Domain\Domain.Exceptions\Domain.Exceptions.csproj"/> <ProjectReference Include="..\..\Domain\Domain.Exceptions\Domain.Exceptions.csproj" />
<ProjectReference Include="..\..\Infrastructure\Infrastructure.Sql\Infrastructure.Sql.csproj"/> <ProjectReference Include="..\..\Infrastructure\Infrastructure.Sql\Infrastructure.Sql.csproj" />
<ProjectReference Include="..\..\Shared\Shared.Contracts\Shared.Contracts.csproj"/> <ProjectReference Include="..\..\Shared\Shared.Contracts\Shared.Contracts.csproj" />
<ProjectReference Include="..\..\Shared\Shared.Application\Shared.Application.csproj"/> <ProjectReference Include="..\..\Shared\Shared.Application\Shared.Application.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -11,7 +11,10 @@ namespace Features.UserManagement.Queries.GetAllUsers;
public class GetAllUsersHandler(IUserAccountRepository repository) public class GetAllUsersHandler(IUserAccountRepository repository)
: IRequestHandler<GetAllUsersQuery, IEnumerable<UserAccount>> : IRequestHandler<GetAllUsersQuery, IEnumerable<UserAccount>>
{ {
public Task<IEnumerable<UserAccount>> Handle(GetAllUsersQuery request, CancellationToken cancellationToken) public Task<IEnumerable<UserAccount>> Handle(
GetAllUsersQuery request,
CancellationToken cancellationToken
)
{ {
return repository.GetAllAsync(request.Limit, request.Offset); return repository.GetAllAsync(request.Limit, request.Offset);
} }

View File

@@ -13,7 +13,10 @@ public class GetUserByIdHandler(IUserAccountRepository repository)
: IRequestHandler<GetUserByIdQuery, UserAccount> : IRequestHandler<GetUserByIdQuery, UserAccount>
{ {
/// <exception cref="NotFoundException">Thrown when no user account exists with the given ID.</exception> /// <exception cref="NotFoundException">Thrown when no user account exists with the given ID.</exception>
public async Task<UserAccount> Handle(GetUserByIdQuery request, CancellationToken cancellationToken) public async Task<UserAccount> Handle(
GetUserByIdQuery request,
CancellationToken cancellationToken
)
{ {
UserAccount? user = await repository.GetByIdAsync(request.UserAccountId); UserAccount? user = await repository.GetByIdAsync(request.UserAccountId);
if (user is null) if (user is null)

View File

@@ -20,10 +20,7 @@ public interface IUserAccountRepository
/// <param name="limit">The maximum number of records to return, or <c>null</c> for no limit.</param> /// <param name="limit">The maximum number of records to return, or <c>null</c> for no limit.</param>
/// <param name="offset">The number of records to skip, or <c>null</c> for no offset.</param> /// <param name="offset">The number of records to skip, or <c>null</c> for no offset.</param>
/// <returns>The collection of matching <see cref="Domain.Entities.UserAccount" /> records.</returns> /// <returns>The collection of matching <see cref="Domain.Entities.UserAccount" /> records.</returns>
Task<IEnumerable<UserAccount>> GetAllAsync( Task<IEnumerable<UserAccount>> GetAllAsync(int? limit, int? offset);
int? limit,
int? offset
);
/// <summary> /// <summary>
/// Updates an existing user account's details. /// Updates an existing user account's details.

View File

@@ -42,10 +42,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// <param name="offset">The number of records to skip, or <c>null</c> for no offset.</param> /// <param name="offset">The number of records to skip, or <c>null</c> for no offset.</param>
/// <returns>The collection of matching <see cref="Domain.Entities.UserAccount" /> records.</returns> /// <returns>The collection of matching <see cref="Domain.Entities.UserAccount" /> records.</returns>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception> /// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
public async Task<IEnumerable<UserAccount>> GetAllAsync( public async Task<IEnumerable<UserAccount>> GetAllAsync(int? limit, int? offset)
int? limit,
int? offset
)
{ {
await using DbConnection connection = await CreateConnection(); await using DbConnection connection = await CreateConnection();
await using DbCommand command = connection.CreateCommand(); await using DbCommand command = connection.CreateCommand();
@@ -61,7 +58,8 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
await using DbDataReader reader = await command.ExecuteReaderAsync(); await using DbDataReader reader = await command.ExecuteReaderAsync();
List<UserAccount> users = new(); List<UserAccount> users = new();
while (await reader.ReadAsync()) users.Add(MapToEntity(reader)); while (await reader.ReadAsync())
users.Add(MapToEntity(reader));
return users; return users;
} }
@@ -111,9 +109,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// <param name="username">The username to search for.</param> /// <param name="username">The username to search for.</param>
/// <returns>The matching <see cref="Domain.Entities.UserAccount" />, or <c>null</c> if not found.</returns> /// <returns>The matching <see cref="Domain.Entities.UserAccount" />, or <c>null</c> if not found.</returns>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception> /// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
public async Task<UserAccount?> GetByUsernameAsync( public async Task<UserAccount?> GetByUsernameAsync(string username)
string username
)
{ {
await using DbConnection connection = await CreateConnection(); await using DbConnection connection = await CreateConnection();
await using DbCommand command = connection.CreateCommand(); await using DbCommand command = connection.CreateCommand();
@@ -132,9 +128,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// <param name="email">The email address to search for.</param> /// <param name="email">The email address to search for.</param>
/// <returns>The matching <see cref="Domain.Entities.UserAccount" />, or <c>null</c> if not found.</returns> /// <returns>The matching <see cref="Domain.Entities.UserAccount" />, or <c>null</c> if not found.</returns>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception> /// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
public async Task<UserAccount?> GetByEmailAsync( public async Task<UserAccount?> GetByEmailAsync(string email)
string email
)
{ {
await using DbConnection connection = await CreateConnection(); await using DbConnection connection = await CreateConnection();
await using DbCommand command = connection.CreateCommand(); await using DbCommand command = connection.CreateCommand();
@@ -152,9 +146,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// </summary> /// </summary>
/// <param name="reader">The data reader positioned on the row to map.</param> /// <param name="reader">The data reader positioned on the row to map.</param>
/// <returns>The mapped <see cref="Domain.Entities.UserAccount" /> instance.</returns> /// <returns>The mapped <see cref="Domain.Entities.UserAccount" /> instance.</returns>
protected override UserAccount MapToEntity( protected override UserAccount MapToEntity(DbDataReader reader)
DbDataReader reader
)
{ {
return new UserAccount return new UserAccount
{ {
@@ -168,9 +160,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
? null ? null
: reader.GetDateTime(reader.GetOrdinal("UpdatedAt")), : reader.GetDateTime(reader.GetOrdinal("UpdatedAt")),
DateOfBirth = reader.GetDateTime(reader.GetOrdinal("DateOfBirth")), DateOfBirth = reader.GetDateTime(reader.GetOrdinal("DateOfBirth")),
Timer = reader.IsDBNull(reader.GetOrdinal("Timer")) Timer = reader.IsDBNull(reader.GetOrdinal("Timer")) ? null : (byte[])reader["Timer"],
? null
: (byte[])reader["Timer"]
}; };
} }
@@ -181,11 +171,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// <param name="command">The command to add the parameter to.</param> /// <param name="command">The command to add the parameter to.</param>
/// <param name="name">The parameter name (including any prefix, e.g. "@Username").</param> /// <param name="name">The parameter name (including any prefix, e.g. "@Username").</param>
/// <param name="value">The parameter value, or <c>null</c> to bind <see cref="DBNull.Value" />.</param> /// <param name="value">The parameter value, or <c>null</c> to bind <see cref="DBNull.Value" />.</param>
private static void AddParameter( private static void AddParameter(DbCommand command, string name, object? value)
DbCommand command,
string name,
object? value
)
{ {
DbParameter p = command.CreateParameter(); DbParameter p = command.CreateParameter();
p.ParameterName = name; p.ParameterName = name;