mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-29 18:21:08 +00:00
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using CleanArchitecture.Domain.Interfaces.Repositories;
|
|
using CleanArchitecture.Proto.Tenants;
|
|
using Grpc.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CleanArchitecture.Application.gRPC;
|
|
|
|
public sealed class TenantsApiImplementation : TenantsApi.TenantsApiBase
|
|
{
|
|
private readonly ITenantRepository _tenantRepository;
|
|
|
|
public TenantsApiImplementation(ITenantRepository tenantRepository)
|
|
{
|
|
_tenantRepository = tenantRepository;
|
|
}
|
|
|
|
public override async Task<GetTenantsByIdsResult> GetByIds(
|
|
GetTenantsByIdsRequest request,
|
|
ServerCallContext context)
|
|
{
|
|
var idsAsGuids = new List<Guid>(request.Ids.Count);
|
|
|
|
foreach (var id in request.Ids)
|
|
{
|
|
if (Guid.TryParse(id, out var parsed))
|
|
{
|
|
idsAsGuids.Add(parsed);
|
|
}
|
|
}
|
|
|
|
var tenants = await _tenantRepository
|
|
.GetAllNoTracking()
|
|
.IgnoreQueryFilters()
|
|
.Where(tenant => idsAsGuids.Contains(tenant.Id))
|
|
.Select(tenant => new Tenant
|
|
{
|
|
Id = tenant.Id.ToString(),
|
|
Name = tenant.Name,
|
|
DeletedAt = tenant.DeletedAt == null ? "": tenant.DeletedAt.ToString()
|
|
})
|
|
.ToListAsync();
|
|
|
|
var result = new GetTenantsByIdsResult();
|
|
|
|
result.Tenants.AddRange(tenants);
|
|
|
|
return result;
|
|
}
|
|
} |