Перевести «не найдено» пользователя у оператора на исключение
ci / build-test (pull_request) Successful in 3m7s

TenantAdminService.GetAsync бросает NotFoundException вместо null; эндпоинт деталей без 404-проверки.
This commit is contained in:
2026-09-13 18:49:18 +03:00
parent 891a894aed
commit 75de70e09c
3 changed files with 15 additions and 16 deletions
@@ -1,6 +1,7 @@
using Deal.Modules.Tenants.Application.Abstractions;
using Deal.Modules.Tenants.Application.Models;
using Deal.SharedKernel;
using Deal.SharedKernel.Errors;
using Deal.SharedKernel.Utilities;
namespace Deal.Modules.Tenants.Application.Services;
@@ -17,6 +18,9 @@ public sealed class TenantAdminService(
// Случайные байты одноразового пароля владельца: 12 → ровно 16 символов Base64Url (как InviteCodeGenerator).
private const int InitialPasswordRandomByteCount = 12;
// Имя сущности для текста ошибки «не найдено» (пользователь = тенант с его окружением).
private const string TenantEntityName = "Пользователь";
/// <summary>
/// Создаёт тенанта оператором
/// </summary>
@@ -103,14 +107,12 @@ public sealed class TenantAdminService(
/// Детали тенанта с пользователями
/// </summary>
/// <param name="id">Идентификатор тенанта.</param>
/// <returns>Детали и пользователи тенанта (по CreatedAt) или null, если тенанта нет.</returns>
public async Task<TenantDetailDto?> GetAsync(Guid id, CancellationToken ct)
/// <returns>Детали и пользователи тенанта (по CreatedAt).</returns>
/// <exception cref="NotFoundException">Тенант не найден.</exception>
public async Task<TenantDetailDto> GetAsync(Guid id, CancellationToken ct)
{
var tenant = await tenantRepository.FindByIdAsync(id, ct);
if (tenant is null)
{
return null;
}
var tenant = await tenantRepository.FindByIdAsync(id, ct)
?? throw new NotFoundException(TenantEntityName, id.ToString("N"));
IReadOnlyList<UserIdentityDto> users = await authStore.ListUsersByTenantIdAsync(id, ct);
return new TenantDetailDto(tenant.Id, tenant.Name, tenant.Status, tenant.CreatedAt, users);