diff --git a/src/dotnet/Suspectus.Gandalf.Palantir.Api/Controllers/TenantController.cs b/src/dotnet/Suspectus.Gandalf.Palantir.Api/Controllers/TenantController.cs index fa3cbfb..0dce1c5 100644 --- a/src/dotnet/Suspectus.Gandalf.Palantir.Api/Controllers/TenantController.cs +++ b/src/dotnet/Suspectus.Gandalf.Palantir.Api/Controllers/TenantController.cs @@ -1,10 +1,10 @@ -using System.ComponentModel.DataAnnotations; using HashidsNet; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Suspectus.Gandalf.Core.Abstractions.DTOs; using Suspectus.Gandalf.Palantir.Data.Database; +using Suspectus.Gandalf.Palantir.Data.Dto.Tenant; +using Suspectus.Gandalf.Palantir.Data.Entities.Base; namespace Suspectus.Gandalf.Palantir.Api.Controllers; @@ -26,6 +26,41 @@ public class TenantController : ControllerBase public async Task Get(CancellationToken cancellationToken) { var tenantEntities = await _context.Tenants.ToListAsync(cancellationToken: cancellationToken); - return Ok(tenantEntities); + var dtos = tenantEntities.Select(x => new TenantGridViewDto + { + Id = _hashids.EncodeLong(x.Id!.Value), + Name = x.Name, + IsMaster = x.IsMaster, + OwnerId = _hashids.EncodeLong(x.OwnerId), + Visibility = x.Visibility + }); + return Ok(dtos); + } + + [HttpGet("{idHash}")] + public async Task Get(CancellationToken cancellationToken, string idHash) + { + if (!_hashids.TryDecodeSingleLong(idHash, out var id)) + { + return BadRequest(); + } + + var tenant = await _context.Tenants.SingleOrDefaultAsync(x => x.Id!.Value == id, cancellationToken: cancellationToken); + + if (tenant is null) + { + return NotFound(); + } + + var dto = new TenantGridViewDto + { + Id = _hashids.EncodeLong(tenant.Id!.Value), + Name = tenant.Name, + IsMaster = tenant.IsMaster, + OwnerId = _hashids.EncodeLong(tenant.OwnerId), + Visibility = tenant.Visibility + }; + + return Ok(dto); } } \ No newline at end of file diff --git a/src/dotnet/Suspectus.Gandalf.Palantir.Data/Dto/Tenant/TenantGridViewDto.cs b/src/dotnet/Suspectus.Gandalf.Palantir.Data/Dto/Tenant/TenantGridViewDto.cs new file mode 100644 index 0000000..38adcb8 --- /dev/null +++ b/src/dotnet/Suspectus.Gandalf.Palantir.Data/Dto/Tenant/TenantGridViewDto.cs @@ -0,0 +1,12 @@ +using Suspectus.Gandalf.Palantir.Data.Entities.Base; + +namespace Suspectus.Gandalf.Palantir.Data.Dto.Tenant; + +public class TenantGridViewDto +{ + public required string Id { get; set; } + public required string Name { get; set; } + public required bool IsMaster { get; set; } + public required string OwnerId { get; set; } + public required EntityVisibility Visibility { get; set; } +} \ No newline at end of file