using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ZeroFramework.DeviceCenter.Application.Models.Tenants;
using ZeroFramework.DeviceCenter.Application.PermissionProviders;
using ZeroFramework.DeviceCenter.Application.Services.Generics;
using ZeroFramework.DeviceCenter.Application.Services.Tenants;
namespace ZeroFramework.DeviceCenter.API.Controllers
{
///
/// For more information on enabling Web API for empty projects
///
[Route("api/[controller]")]
[ApiController, ApiExplorerSettings(IgnoreApi = true)]
public class TenantsController(ITenantApplicationService tenantService) : ControllerBase
{
private readonly ITenantApplicationService _tenantService = tenantService;
// GET: api/
[HttpGet]
[Authorize(TenantPermissions.Tenants.Default)]
public async Task> Get([FromQuery] PagedRequestModel model)
{
return await _tenantService.GetListAsync(model);
}
// GET api//5
[HttpGet("{id}")]
[Authorize(TenantPermissions.Tenants.Default)]
public async Task Get(Guid id)
{
return await _tenantService.GetAsync(id);
}
// POST api/
[HttpPost]
[Authorize(TenantPermissions.Tenants.Create)]
public async Task Post([FromBody] TenantCreateOrUpdateRequestModel value)
{
return await _tenantService.CreateAsync(value);
}
// PUT api//5
[HttpPut("{id}")]
[Authorize(TenantPermissions.Tenants.Edit)]
public async Task Put(Guid id, [FromBody] TenantCreateOrUpdateRequestModel value)
{
value.Id = id;
return await _tenantService.UpdateAsync(id, value);
}
// DELETE api//5
[HttpDelete("{id}")]
[Authorize(TenantPermissions.Tenants.Delete)]
public async Task Delete(Guid id)
{
await _tenantService.DeleteAsync(id);
}
[HttpGet("{id}/default-connection-string")]
[Authorize(TenantPermissions.Tenants.ConnectionString)]
public async Task GetDefaultConnectionStringAsync(Guid id)
{
return await _tenantService.GetDefaultConnectionStringAsync(id);
}
[HttpPut("{id}/default-connection-string")]
[Authorize(TenantPermissions.Tenants.ConnectionString)]
public async Task UpdateDefaultConnectionStringAsync(Guid id, string defaultConnectionString)
{
await _tenantService.UpdateDefaultConnectionStringAsync(id, defaultConnectionString);
}
[HttpDelete("{id}/default-connection-string")]
[Authorize(TenantPermissions.Tenants.ConnectionString)]
public async Task DeleteDefaultConnectionStringAsync(Guid id)
{
await _tenantService.DeleteDefaultConnectionStringAsync(id);
}
}
}