Migrate UserManagement to a vertical slice (Features.UserManagement)

Same pattern as the Breweries migration: Service.UserManagement and the
UserAccount repository fold into Features.UserManagement, with MediatR
queries replacing UserService. UpdateUserCommand/Handler carry forward
IUserService.UpdateAsync as-is (it has no HTTP route today, and adding one
is a separate decision from this migration). Adds handler/repository test
coverage that didn't exist before, since Service.UserManagement had no
test project.
This commit is contained in:
Aaron Po
2026-06-20 00:02:27 -04:00
parent a8c1b17095
commit 6db004066f
24 changed files with 267 additions and 118 deletions

View File

@@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Domain\Domain.Exceptions\Domain.Exceptions.csproj" />
<ProjectReference
Include="..\..\Infrastructure\Infrastructure.Repository\Infrastructure.Repository.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,34 +0,0 @@
using Domain.Entities;
namespace Service.UserManagement.User;
/// <summary>
/// Defines operations for retrieving and updating user accounts.
/// </summary>
public interface IUserService
{
/// <summary>
/// Retrieves all user accounts, optionally paginated.
/// </summary>
/// <param name="limit">The maximum number of results to return, or <c>null</c> for no limit.</param>
/// <param name="offset">The number of results to skip, or <c>null</c> to start from the beginning.</param>
/// <returns>A collection of <see cref="UserAccount"/> entities.</returns>
Task<IEnumerable<UserAccount>> GetAllAsync(
int? limit = null,
int? offset = null
);
/// <summary>
/// Retrieves a user account by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the user account.</param>
/// <returns>The matching <see cref="UserAccount"/>.</returns>
Task<UserAccount> GetByIdAsync(Guid id);
/// <summary>
/// Updates an existing user account.
/// </summary>
/// <param name="userAccount">The user account containing the updated data.</param>
/// <returns>A task that completes once the update has finished.</returns>
Task UpdateAsync(UserAccount userAccount);
}

View File

@@ -1,50 +0,0 @@
using Domain.Entities;
using Domain.Exceptions;
using Infrastructure.Repository.UserAccount;
namespace Service.UserManagement.User;
/// <summary>
/// Handles retrieval and update of user accounts.
/// </summary>
/// <param name="repository">Repository used to persist and query user account data.</param>
public class UserService(IUserAccountRepository repository) : IUserService
{
/// <summary>
/// Retrieves all user accounts, optionally paginated.
/// </summary>
/// <param name="limit">The maximum number of results to return, or <c>null</c> for no limit.</param>
/// <param name="offset">The number of results to skip, or <c>null</c> to start from the beginning.</param>
/// <returns>A collection of <see cref="UserAccount"/> entities.</returns>
public async Task<IEnumerable<UserAccount>> GetAllAsync(
int? limit = null,
int? offset = null
)
{
return await repository.GetAllAsync(limit, offset);
}
/// <summary>
/// Retrieves a user account by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the user account.</param>
/// <returns>The matching <see cref="UserAccount"/>.</returns>
/// <exception cref="NotFoundException">Thrown when no user account exists with the given <paramref name="id"/>.</exception>
public async Task<UserAccount> GetByIdAsync(Guid id)
{
var user = await repository.GetByIdAsync(id);
if (user is null)
throw new NotFoundException($"User with ID {id} not found");
return user;
}
/// <summary>
/// Updates an existing user account.
/// </summary>
/// <param name="userAccount">The user account containing the updated data.</param>
/// <returns>A task that completes once the update has finished.</returns>
public async Task UpdateAsync(UserAccount userAccount)
{
await repository.UpdateAsync(userAccount);
}
}