| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Common.Multitenancy; |
| | | 4 | | using Elsa.Common.Serialization; |
| | | 5 | | using Elsa.Workflows; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Tenants.Endpoints.Tenants.Add; |
| | | 8 | | |
| | 0 | 9 | | public class Endpoint(ITenantService tenantService, IIdentityGenerator identityGenerator, ITenantStore tenantStore) : El |
| | | 10 | | { |
| | | 11 | | public override void Configure() |
| | | 12 | | { |
| | 0 | 13 | | Post("/tenants"); |
| | 0 | 14 | | ConfigurePermissions("write:tenants"); |
| | 0 | 15 | | } |
| | | 16 | | |
| | | 17 | | public override async Task HandleAsync(NewTenant req, CancellationToken ct) |
| | | 18 | | { |
| | 0 | 19 | | var tenant = new Tenant |
| | 0 | 20 | | { |
| | 0 | 21 | | Id = req.IsDefault ? string.Empty : req.Id ?? identityGenerator.GenerateId(), |
| | 0 | 22 | | TenantId = req.TenantId, |
| | 0 | 23 | | Name = req.Name.Trim(), |
| | 0 | 24 | | Configuration = Serializers.DeserializeConfiguration(req.Configuration) |
| | 0 | 25 | | }; |
| | 0 | 26 | | await tenantStore.AddAsync(tenant, ct); |
| | 0 | 27 | | await tenantService.RefreshAsync(ct); |
| | 0 | 28 | | await Send.OkAsync(tenant, ct); |
| | 0 | 29 | | } |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public class NewTenant |
| | | 33 | | { |
| | | 34 | | public bool IsDefault { get; set; } |
| | | 35 | | public string? Id { get; set; } |
| | | 36 | | public string? TenantId { get; set; } |
| | | 37 | | public string Name { get; set; } = default!; |
| | | 38 | | public JsonElement? Configuration { get; set; } |
| | | 39 | | } |