| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Common.Multitenancy; |
| | | 4 | | using Elsa.Common.Serialization; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Tenants.Endpoints.Tenants.Update; |
| | | 7 | | |
| | | 8 | | public class Endpoint(ITenantService tenantService, ITenantStore tenantStore) : ElsaEndpoint<UpdatedTenant, Tenant> |
| | | 9 | | { |
| | | 10 | | public override void Configure() |
| | | 11 | | { |
| | | 12 | | Post("/tenants/{id}"); |
| | | 13 | | ConfigurePermissions("write:tenants"); |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | public override async Task HandleAsync(UpdatedTenant req, CancellationToken ct) |
| | | 17 | | { |
| | | 18 | | var id = Route<string>("id")!; |
| | | 19 | | if (id == "-") id = string.Empty; |
| | | 20 | | var tenant = await tenantStore.FindAsync(id, ct); |
| | | 21 | | |
| | | 22 | | if (tenant == null) |
| | | 23 | | { |
| | | 24 | | await Send.NotFoundAsync(ct); |
| | | 25 | | return; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | tenant.TenantId = req.TenantId; |
| | | 29 | | tenant.Name = req.Name.Trim(); |
| | | 30 | | tenant.Configuration = Serializers.DeserializeConfiguration(req.Configuration); |
| | | 31 | | await tenantStore.UpdateAsync(tenant, ct); |
| | | 32 | | await tenantService.RefreshAsync(ct); |
| | | 33 | | await Send.OkAsync(tenant, ct); |
| | | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public class UpdatedTenant |
| | | 38 | | { |
| | 0 | 39 | | public string Id { get; set; } = default!; |
| | 0 | 40 | | public string? TenantId { get; set; } |
| | 0 | 41 | | public string Name { get; set; } = default!; |
| | 0 | 42 | | public JsonElement? Configuration { get; set; } |
| | | 43 | | } |