mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
Format ./web/backend/Features/Features.UserManagement
This commit is contained in:
@@ -7,4 +7,4 @@ namespace Features.UserManagement.Commands.UpdateUser;
|
|||||||
/// Updates an existing user account. Not currently exposed via any HTTP route, carried forward
|
/// Updates an existing user account. Not currently exposed via any HTTP route, carried forward
|
||||||
/// from <c>IUserService.UpdateAsync</c> as-is.
|
/// from <c>IUserService.UpdateAsync</c> as-is.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record UpdateUserCommand(UserAccount UserAccount) : IRequest;
|
public record UpdateUserCommand(UserAccount UserAccount) : IRequest;
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ public class UpdateUserHandler(IUserAccountRepository repository)
|
|||||||
{
|
{
|
||||||
return repository.UpdateAsync(request.UserAccount);
|
return repository.UpdateAsync(request.UserAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ public class UserController(IMediator mediator) : ControllerBase
|
|||||||
UserAccount user = await mediator.Send(new GetUserByIdQuery(id));
|
UserAccount user = await mediator.Send(new GetUserByIdQuery(id));
|
||||||
return Ok(user);
|
return Ok(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ public static class FeaturesUserManagementServiceCollectionExtensions
|
|||||||
services.AddScoped<IUserAccountRepository, UserAccountRepository>();
|
services.AddScoped<IUserAccountRepository, UserAccountRepository>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ namespace Features.UserManagement.Queries.GetAllUsers;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a paginated list of user accounts.
|
/// Retrieves a paginated list of user accounts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record GetAllUsersQuery(int? Limit, int? Offset) : IRequest<IEnumerable<UserAccount>>;
|
public record GetAllUsersQuery(int? Limit, int? Offset) : IRequest<IEnumerable<UserAccount>>;
|
||||||
|
|||||||
@@ -13,11 +13,14 @@ 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)
|
||||||
throw new NotFoundException($"User with ID {request.UserAccountId} not found");
|
throw new NotFoundException($"User with ID {request.UserAccountId} not found");
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ namespace Features.UserManagement.Queries.GetUserById;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a single user account by its unique identifier.
|
/// Retrieves a single user account by its unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record GetUserByIdQuery(Guid UserAccountId) : IRequest<UserAccount>;
|
public record GetUserByIdQuery(Guid UserAccountId) : IRequest<UserAccount>;
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -50,4 +47,4 @@ public interface IUserAccountRepository
|
|||||||
/// <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>
|
||||||
Task<UserAccount?> GetByEmailAsync(string email);
|
Task<UserAccount?> GetByEmailAsync(string email);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,15 +171,11 @@ 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;
|
||||||
p.Value = value ?? DBNull.Value;
|
p.Value = value ?? DBNull.Value;
|
||||||
command.Parameters.Add(p);
|
command.Parameters.Add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user