2020-12-10 15:57:59 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core.Integrations;
|
|
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
//[ZeroAuthorize(Permissions.Sections.Spaces, PermissionsValue.True)]
|
|
|
|
|
public class IntegrationsController : BackofficeController
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
IIntegrationsCollection Integrations;
|
|
|
|
|
IIntegrationTypeService Types;
|
2020-12-10 15:57:59 +01:00
|
|
|
|
2020-12-16 13:22:18 +01:00
|
|
|
public IntegrationsController(IIntegrationsCollection integrations, IIntegrationTypeService types)
|
2020-12-10 15:57:59 +01:00
|
|
|
{
|
|
|
|
|
Integrations = integrations;
|
2020-12-16 13:22:18 +01:00
|
|
|
Types = types;
|
2020-12-10 15:57:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
available = await Types.GetAvailable(),
|
|
|
|
|
activated = await Types.GetActivated()
|
2020-12-10 15:57:59 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult GetEmptySettings([FromQuery] string alias)
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
IIntegrationType integration = Types.GetByAlias(alias);
|
|
|
|
|
IIntegration model = integration != null ? Activator.CreateInstance(integration.SettingsType) as IIntegration : null;
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
if (model != null)
|
|
|
|
|
{
|
|
|
|
|
model.IntegrationAlias = integration.Alias;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(Edit(model));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetSettingsByAlias([FromQuery] string alias)
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
IIntegration content = await Integrations.GetByAlias(alias);
|
2020-12-10 15:57:59 +01:00
|
|
|
return Ok(Edit(content));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> GetSettingsById([FromQuery] string id)
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
IIntegration content = await Integrations.GetById(id);
|
2020-12-10 15:57:59 +01:00
|
|
|
return Ok(Edit(content));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-12-16 13:22:18 +01:00
|
|
|
public async Task<IActionResult> Save([FromBody] IIntegration model)
|
2020-12-10 15:57:59 +01:00
|
|
|
{
|
|
|
|
|
return Ok(await Integrations.Save(model));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id)
|
|
|
|
|
{
|
2020-12-16 13:22:18 +01:00
|
|
|
return Ok(await Integrations.DeleteById(id));
|
2020-12-10 15:57:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|