update features docs

This commit is contained in:
Aaron Po
2026-08-04 06:18:30 -04:00
parent 2ed655e03d
commit 88abb8e995
46 changed files with 65 additions and 671 deletions

View File

@@ -3,10 +3,6 @@ using MediatR;
namespace Features.UserManagement.Commands.UpdateUser;
/// <summary>
/// Handles <see cref="UpdateUserCommand" /> by persisting changes to an existing user account.
/// </summary>
/// <param name="repository">Repository used to persist the updated user account.</param>
public class UpdateUserHandler(IUserAccountRepository repository)
: IRequestHandler<UpdateUserCommand>
{

View File

@@ -6,20 +6,12 @@ using Microsoft.AspNetCore.Mvc;
namespace Features.UserManagement.Controllers;
/// <summary>
/// Provides read-only endpoints for retrieving user accounts.
/// </summary>
/// <param name="mediator">Used to dispatch user queries to their handlers.</param>
[ApiController]
[Route("api/[controller]")]
public class UserController(IMediator mediator) : ControllerBase
{
/// <summary>
/// Retrieves a paginated list of user accounts.
/// </summary>
/// <param name="limit">The maximum number of user accounts to return, or <c>null</c> for no limit.</param>
/// <param name="offset">The number of user accounts to skip before returning results, or <c>null</c> for no offset.</param>
/// <returns>A <c>200 OK</c> result containing the collection of <see cref="UserAccount" /> entities.</returns>
/// <param name="limit"><c>null</c> for no limit.</param>
/// <param name="offset"><c>null</c> for no offset.</param>
[HttpGet]
public async Task<ActionResult<IEnumerable<UserAccount>>> GetAll(
[FromQuery] int? limit,
@@ -30,11 +22,6 @@ public class UserController(IMediator mediator) : ControllerBase
return Ok(users);
}
/// <summary>
/// Retrieves a single user account by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the user account to retrieve.</param>
/// <returns>A <c>200 OK</c> result containing the matching <see cref="UserAccount" />.</returns>
[HttpGet("{id:guid}")]
public async Task<ActionResult<UserAccount>> GetById(Guid id)
{

View File

@@ -3,9 +3,6 @@ using Microsoft.Extensions.DependencyInjection;
namespace Features.UserManagement.DependencyInjection;
/// <summary>
/// Registers the services owned by the UserManagement feature slice.
/// </summary>
public static class FeaturesUserManagementServiceCollectionExtensions
{
public static IServiceCollection AddFeaturesUserManagement(this IServiceCollection services)

View File

@@ -4,10 +4,6 @@ using MediatR;
namespace Features.UserManagement.Queries.GetAllUsers;
/// <summary>
/// Handles <see cref="GetAllUsersQuery" /> by retrieving a paginated list of user accounts.
/// </summary>
/// <param name="repository">Repository used to query user account data.</param>
public class GetAllUsersHandler(IUserAccountRepository repository)
: IRequestHandler<GetAllUsersQuery, IEnumerable<UserAccount>>
{

View File

@@ -3,7 +3,4 @@ using MediatR;
namespace Features.UserManagement.Queries.GetAllUsers;
/// <summary>
/// Retrieves a paginated list of user accounts.
/// </summary>
public record GetAllUsersQuery(int? Limit, int? Offset) : IRequest<IEnumerable<UserAccount>>;

View File

@@ -5,10 +5,6 @@ using MediatR;
namespace Features.UserManagement.Queries.GetUserById;
/// <summary>
/// Handles <see cref="GetUserByIdQuery" /> by looking up the matching user account.
/// </summary>
/// <param name="repository">Repository used to query user account data.</param>
public class GetUserByIdHandler(IUserAccountRepository repository)
: IRequestHandler<GetUserByIdQuery, UserAccount>
{

View File

@@ -3,7 +3,4 @@ using MediatR;
namespace Features.UserManagement.Queries.GetUserById;
/// <summary>
/// Retrieves a single user account by its unique identifier.
/// </summary>
public record GetUserByIdQuery(Guid UserAccountId) : IRequest<UserAccount>;

View File

@@ -8,43 +8,29 @@ namespace Features.UserManagement.Repository;
public interface IUserAccountRepository
{
/// <summary>
/// Retrieves a user account by its unique identifier.
/// Retrieves a user account by its unique identifier, or <c>null</c> if not found.
/// </summary>
/// <param name="id">The unique identifier of the user account.</param>
/// <returns>The matching <see cref="Domain.Entities.UserAccount" />, or <c>null</c> if not found.</returns>
Task<UserAccount?> GetByIdAsync(Guid id);
/// <summary>
/// Retrieves all user accounts, optionally paginated.
/// </summary>
/// <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>
/// <returns>The collection of matching <see cref="Domain.Entities.UserAccount" /> records.</returns>
/// <param name="limit"><c>null</c> for no limit.</param>
/// <param name="offset"><c>null</c> for no offset.</param>
Task<IEnumerable<UserAccount>> GetAllAsync(int? limit, int? offset);
/// <summary>
/// Updates an existing user account's details.
/// </summary>
/// <param name="userAccount">The user account containing updated values. Must have a valid <c>UserAccountId</c>.</param>
/// <param name="userAccount">Must have a valid <c>UserAccountId</c>.</param>
Task UpdateAsync(UserAccount userAccount);
/// <summary>
/// Deletes a user account by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the user account to delete.</param>
Task DeleteAsync(Guid id);
/// <summary>
/// Retrieves a user account by username.
/// Retrieves a user account by username, or <c>null</c> if not found.
/// </summary>
/// <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>
Task<UserAccount?> GetByUsernameAsync(string username);
/// <summary>
/// Retrieves a user account by email address.
/// Retrieves a user account by email address, or <c>null</c> if not found.
/// </summary>
/// <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>
Task<UserAccount?> GetByEmailAsync(string email);
}

View File

@@ -9,17 +9,12 @@ namespace Features.UserManagement.Repository;
/// ADO.NET-based implementation of <see cref="IUserAccountRepository" /> backed by SQL Server
/// stored procedures.
/// </summary>
/// <param name="connectionFactory">The factory used to create database connections.</param>
public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
: Repository<UserAccount>(connectionFactory),
IUserAccountRepository
{
/// <summary>
/// Retrieves a user account by ID using the <c>usp_GetUserAccountById</c> stored procedure.
/// </summary>
/// <param name="id">The unique identifier of the user account.</param>
/// <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>
/// <summary>Uses the <c>usp_GetUserAccountById</c> stored procedure.</summary>
/// <inheritdoc />
public async Task<UserAccount?> GetByIdAsync(Guid id)
{
await using DbConnection connection = await CreateConnection();
@@ -34,14 +29,10 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
}
/// <summary>
/// Retrieves all user accounts, optionally paginated, using the <c>usp_GetAllUserAccounts</c>
/// stored procedure. The <c>@Limit</c> and <c>@Offset</c> parameters are only added when their
/// corresponding argument has a value.
/// Uses the <c>usp_GetAllUserAccounts</c> stored procedure. The <c>@Limit</c> and <c>@Offset</c>
/// parameters are only added when their corresponding argument has a value.
/// </summary>
/// <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>
/// <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>
/// <inheritdoc />
public async Task<IEnumerable<UserAccount>> GetAllAsync(int? limit, int? offset)
{
await using DbConnection connection = await CreateConnection();
@@ -68,8 +59,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
/// Updates a user account's username, first name, last name, email, and date of birth using
/// the <c>usp_UpdateUserAccount</c> stored procedure.
/// </summary>
/// <param name="userAccount">The user account containing updated values. Must have a valid <c>UserAccountId</c>.</param>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
/// <inheritdoc />
public async Task UpdateAsync(UserAccount userAccount)
{
await using DbConnection connection = await CreateConnection();
@@ -87,11 +77,8 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
await command.ExecuteNonQueryAsync();
}
/// <summary>
/// Deletes a user account by ID using the <c>usp_DeleteUserAccount</c> stored procedure.
/// </summary>
/// <param name="id">The unique identifier of the user account to delete.</param>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
/// <summary>Uses the <c>usp_DeleteUserAccount</c> stored procedure.</summary>
/// <inheritdoc />
public async Task DeleteAsync(Guid id)
{
await using DbConnection connection = await CreateConnection();
@@ -103,12 +90,8 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
await command.ExecuteNonQueryAsync();
}
/// <summary>
/// Retrieves a user account by username using the <c>usp_GetUserAccountByUsername</c> stored procedure.
/// </summary>
/// <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>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
/// <summary>Uses the <c>usp_GetUserAccountByUsername</c> stored procedure.</summary>
/// <inheritdoc />
public async Task<UserAccount?> GetByUsernameAsync(string username)
{
await using DbConnection connection = await CreateConnection();
@@ -122,12 +105,8 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
return await reader.ReadAsync() ? MapToEntity(reader) : null;
}
/// <summary>
/// Retrieves a user account by email address using the <c>usp_GetUserAccountByEmail</c> stored procedure.
/// </summary>
/// <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>
/// <exception cref="Microsoft.Data.SqlClient.SqlException">Thrown when the database command fails.</exception>
/// <summary>Uses the <c>usp_GetUserAccountByEmail</c> stored procedure.</summary>
/// <inheritdoc />
public async Task<UserAccount?> GetByEmailAsync(string email)
{
await using DbConnection connection = await CreateConnection();
@@ -141,11 +120,6 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
return await reader.ReadAsync() ? MapToEntity(reader) : null;
}
/// <summary>
/// Maps the current row of a data reader to a <see cref="Domain.Entities.UserAccount" /> entity.
/// </summary>
/// <param name="reader">The data reader positioned on the row to map.</param>
/// <returns>The mapped <see cref="Domain.Entities.UserAccount" /> instance.</returns>
protected override UserAccount MapToEntity(DbDataReader reader)
{
return new UserAccount
@@ -164,13 +138,7 @@ public class UserAccountRepository(ISqlConnectionFactory connectionFactory)
};
}
/// <summary>
/// Helper method to add a parameter to a database command, converting <c>null</c> values to
/// <see cref="DBNull.Value" />.
/// </summary>
/// <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="value">The parameter value, or <c>null</c> to bind <see cref="DBNull.Value" />.</param>
/// <summary>Converts <c>null</c> values to <see cref="DBNull.Value" /> when adding the parameter.</summary>
private static void AddParameter(DbCommand command, string name, object? value)
{
DbParameter p = command.CreateParameter();