feat(uns): carry created id on UnsMutationResult for equipment create
This commit is contained in:
@@ -8,4 +8,6 @@ namespace ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
/// </summary>
|
||||
/// <param name="Ok">Whether the mutation was applied.</param>
|
||||
/// <param name="Error">The operator-facing failure message, or <c>null</c> on success.</param>
|
||||
public readonly record struct UnsMutationResult(bool Ok, string? Error);
|
||||
/// <param name="CreatedId">On a successful create, the new entity's system id (e.g. the generated
|
||||
/// <c>EQ-…</c> equipment id) so the caller can navigate to it; <c>null</c> for updates/deletes/failures.</param>
|
||||
public readonly record struct UnsMutationResult(bool Ok, string? Error, string? CreatedId = null);
|
||||
|
||||
@@ -539,7 +539,7 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
|
||||
Enabled = input.Enabled,
|
||||
});
|
||||
await db.SaveChangesAsync(ct);
|
||||
return new UnsMutationResult(true, null);
|
||||
return new UnsMutationResult(true, null, equipmentId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -348,6 +348,24 @@ public sealed class UnsTreeServiceEquipmentTests
|
||||
verify.Equipment.Single(e => e.EquipmentId == equipmentId).DriverInstanceId.ShouldBe("DRV-1");
|
||||
}
|
||||
|
||||
/// <summary>CreateEquipmentAsync returns the generated EQ- id in <c>CreatedId</c> so callers can navigate to the new page.</summary>
|
||||
[Fact]
|
||||
public async Task CreateEquipment_returns_generated_id_in_CreatedId()
|
||||
{
|
||||
var dbName = $"uns-eq-createdid-{Guid.NewGuid():N}";
|
||||
UnsTreeTestDb.SeedNamed(dbName);
|
||||
var service = new UnsTreeService(UnsTreeTestDb.Factory(dbName));
|
||||
|
||||
var input = new EquipmentInput("machine-2", "machine_002", "LINE-1",
|
||||
null, null, null, null, null, null, null, null, null, null, null, null, true);
|
||||
|
||||
var result = await service.CreateEquipmentAsync(input);
|
||||
|
||||
result.Ok.ShouldBeTrue();
|
||||
result.CreatedId.ShouldNotBeNull();
|
||||
result.CreatedId!.ShouldStartWith("EQ-");
|
||||
}
|
||||
|
||||
// ----- DeleteEquipment -----
|
||||
|
||||
/// <summary>Deleting equipment removes the row.</summary>
|
||||
|
||||
Reference in New Issue
Block a user