2020-12-10 15:57:59 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-01-15 13:56:50 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-12-10 15:57:59 +01:00
|
|
|
using System.Threading.Tasks;
|
2021-01-15 13:56:50 +01:00
|
|
|
using zero.Core.Collections;
|
2021-01-13 23:50:03 +01:00
|
|
|
using zero.Core.Entities;
|
2020-12-10 15:57:59 +01:00
|
|
|
using zero.Core.Integrations;
|
2021-01-15 13:56:50 +01:00
|
|
|
using zero.Web.Models;
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2021-01-15 13:56:50 +01:00
|
|
|
//[ZeroAuthorize(Permissions.Sections.PREFIX + "commerce", PermissionsValue.Read)]
|
2020-12-10 15:57:59 +01:00
|
|
|
public class IntegrationsController : BackofficeController
|
|
|
|
|
{
|
2021-01-15 13:56:50 +01:00
|
|
|
IIntegrationsCollection Collection;
|
2020-12-10 15:57:59 +01:00
|
|
|
|
2021-01-15 13:56:50 +01:00
|
|
|
public IntegrationsController(IIntegrationsCollection collection)
|
2020-12-10 15:57:59 +01:00
|
|
|
{
|
2021-01-15 13:56:50 +01:00
|
|
|
Collection = collection;
|
|
|
|
|
Collection.WithInactive();
|
2020-12-10 15:57:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-04 17:23:52 +02:00
|
|
|
public EditModel<Integration> GetEmpty([FromQuery] string alias) => Edit(Collection.GetEmpty(alias));
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
|
2021-05-04 17:23:52 +02:00
|
|
|
public async Task<EditModel<Integration>> GetByAlias([FromQuery] string alias) => Edit(await Collection.GetByAlias(alias));
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
|
2021-05-04 17:23:52 +02:00
|
|
|
public async Task<ListResult<Integration>> GetByQuery([FromQuery] ListQuery<Integration> query) => await Collection.GetByQuery(query);
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
|
2021-01-15 13:56:50 +01:00
|
|
|
public async Task<IList<IntegrationTypeWithStatus>> GetTypes() => await Collection.GetTypesWithStatus();
|
2020-12-10 15:57:59 +01:00
|
|
|
|
|
|
|
|
|
2021-01-15 13:56:50 +01:00
|
|
|
[HttpPost]
|
2021-05-04 17:23:52 +02:00
|
|
|
public async Task<EntityResult<Integration>> Save([FromBody] Integration model) => await Collection.Save(model);
|
2020-12-10 15:57:59 +01:00
|
|
|
|
2021-01-15 13:56:50 +01:00
|
|
|
[HttpPost]
|
2021-05-04 17:23:52 +02:00
|
|
|
public async Task<EntityResult<Integration>> SaveActiveState([FromBody] Integration model) => model.IsActive ? await Collection.Activate(model.Alias) : await Collection.Deactivate(model.Alias);
|
2021-01-15 13:56:50 +01:00
|
|
|
|
|
|
|
|
[HttpDelete]
|
2021-05-04 17:23:52 +02:00
|
|
|
public async Task<EntityResult<Integration>> Delete([FromQuery] string alias) => await Collection.Delete(alias);
|
2020-12-10 15:57:59 +01:00
|
|
|
}
|
2021-01-15 13:56:50 +01:00
|
|
|
}
|