mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-07-16 17:47:22 +00:00
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:
@@ -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>
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user