Enhance AbpTenantAppService to support to query tenant by also id.

pull/1810/head
Halil İbrahim Kalkan 6 years ago
parent 56313c91dc
commit 53987e813b

@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.MultiTenancy
{
public interface IAbpTenantAppService : IApplicationService
{
Task<FindTenantResult> FindTenantByNameAsync(string name);
Task<FindTenantResult> FindTenantByIdAsync(Guid id);
}
}

@ -0,0 +1,52 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
using Volo.Abp.MultiTenancy;
namespace Pages.Abp.MultiTenancy
{
public class AbpTenantAppService : ApplicationService, IAbpTenantAppService
{
protected ITenantStore TenantStore { get; }
public AbpTenantAppService(ITenantStore tenantStore)
{
TenantStore = tenantStore;
}
public async Task<FindTenantResult> FindTenantByNameAsync(string name)
{
var tenant = await TenantStore.FindAsync(name);
if (tenant == null)
{
return new FindTenantResult { Success = false };
}
return new FindTenantResult
{
Success = true,
TenantId = tenant.Id,
Name = tenant.Name
};
}
public async Task<FindTenantResult> FindTenantByIdAsync(Guid id)
{
var tenant = await TenantStore.FindAsync(id);
if (tenant == null)
{
return new FindTenantResult { Success = false };
}
return new FindTenantResult
{
Success = true,
TenantId = tenant.Id,
Name = tenant.Name
};
}
}
}

@ -2,56 +2,33 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
namespace Pages.Abp.MultiTenancy
{
[Route("api/abp/multi-tenancy")]
public class AbpTenantController : AbpController
public class AbpTenantController : AbpController, IAbpTenantAppService
{
protected ITenantStore TenantStore { get; }
private readonly IAbpTenantAppService _abpTenantAppService;
public AbpTenantController(ITenantStore tenantStore)
public AbpTenantController(IAbpTenantAppService abpTenantAppService)
{
TenantStore = tenantStore;
_abpTenantAppService = abpTenantAppService;
}
[HttpGet]
[Route("find-tenant/{name}")]
public async Task<FindTenantResult> FindTenantAsync(string name)
[Route("find-tenant/{name}")] //TODO: Remove on v1.0
[Route("tenants/by-name/{name}")]
public async Task<FindTenantResult> FindTenantByNameAsync(string name)
{
var tenant = await TenantStore.FindAsync(name);
if (tenant == null)
{
return new FindTenantResult{Success = false};
}
return new FindTenantResult
{
Success = true,
TenantId = tenant.Id,
Name = tenant.Name
};
return await _abpTenantAppService.FindTenantByNameAsync(name);
}
[HttpGet]
[Route("find-tenant-by-id/{name}")]
[Route("tenants/by-id/{id}")]
public async Task<FindTenantResult> FindTenantByIdAsync(Guid id)
{
var tenant = await TenantStore.FindAsync(id);
if (tenant == null)
{
return new FindTenantResult { Success = false };
}
return new FindTenantResult
{
Success = true,
TenantId = tenant.Id,
Name = tenant.Name
};
return await _abpTenantAppService.FindTenantByIdAsync(id);
}
}
}

@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@ -16,7 +15,6 @@ using System.Reflection;
using Volo.Abp.ApiVersioning;
using Volo.Abp.AspNetCore.Mvc.Conventions;
using Volo.Abp.AspNetCore.Mvc.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Json;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.DependencyInjection;

@ -12,7 +12,7 @@ export class AccountService {
findTenant(tenantName: string): Observable<TenantIdResponse> {
const request: Rest.Request<null> = {
method: 'GET',
url: `/api/abp/multi-tenancy/find-tenant/${tenantName}`,
url: `/api/abp/multi-tenancy/tenants/by-name/${tenantName}`,
};
return this.rest.request<null, TenantIdResponse>(request);

Loading…
Cancel
Save