Init Git
This commit is contained in:
45
AMREZ.EOP.Application/UseCases/Tenancy/ListDomainsUseCase.cs
Normal file
45
AMREZ.EOP.Application/UseCases/Tenancy/ListDomainsUseCase.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Data;
|
||||
using AMREZ.EOP.Abstractions.Applications.Tenancy;
|
||||
using AMREZ.EOP.Abstractions.Applications.UseCases.Tenancy;
|
||||
using AMREZ.EOP.Abstractions.Infrastructures.Common;
|
||||
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
|
||||
using AMREZ.EOP.Contracts.DTOs.Tenancy.ListDomains;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace AMREZ.EOP.Application.UseCases.Tenancy;
|
||||
|
||||
public sealed class ListDomainsUseCase : IListDomainsUseCase
|
||||
{
|
||||
private readonly ITenantResolver _resolver;
|
||||
private readonly IHttpContextAccessor _http;
|
||||
private readonly IUnitOfWork _uow;
|
||||
private readonly ITenantRepository _repo;
|
||||
|
||||
public ListDomainsUseCase(ITenantResolver resolver, IHttpContextAccessor http, IUnitOfWork uow, ITenantRepository repo)
|
||||
{ _resolver = resolver; _http = http; _uow = uow; _repo = repo; }
|
||||
|
||||
public async Task<ListDomainsResponse?> ExecuteAsync(ListDomainsRequest request, CancellationToken ct = default)
|
||||
{
|
||||
var http = _http.HttpContext ?? throw new InvalidOperationException("No HttpContext");
|
||||
var key = string.IsNullOrWhiteSpace(request?.TenantKey) ? null : request!.TenantKey!.Trim().ToLowerInvariant();
|
||||
|
||||
var ctx = _resolver.Resolve(http, hint: null);
|
||||
if (ctx is null) return null;
|
||||
|
||||
await _uow.BeginAsync(ctx, IsolationLevel.ReadCommitted, ct);
|
||||
try
|
||||
{
|
||||
var items = (await _repo.ListDomainsAsync(key, ct))
|
||||
.Select(x => new DomainDto(x.Domain, x.TenantKey, x.IsPlatformBaseDomain, x.IsActive, x.UpdatedAtUtc))
|
||||
.ToList();
|
||||
|
||||
await _uow.CommitAsync(ct);
|
||||
return new ListDomainsResponse(items);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _uow.RollbackAsync(ct);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user