diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs
index df7094e6b9..6458b65364 100644
--- a/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs
+++ b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyCertificateTypeData.cs
@@ -17,7 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
-using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
+using System.Text.Json.Serialization;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
@@ -25,10 +25,12 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
///
/// Model for CompanyCertificateTypeData
/// ]
-/// CompanyCertificate Type Id
-/// description
+/// CompanyCertificate Type Id
+/// description
///
-public record CompanyCertificateTypeData(CompanyCertificateTypeId companyCertificateId, IEnumerable description);
+public record CompanyCertificateTypeData(
+ [property: JsonPropertyName("certificateType")] CompanyCertificateTypeId CompanyCertificateTypeId,
+ IEnumerable Description);
///
/// Model for CertificateTypeDescription
diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
index 477bfc8630..47b0a8bf4e 100644
--- a/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
+++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/StaticDataRepository.cs
@@ -105,12 +105,12 @@ public IAsyncEnumerable GetLicenseTypeData() =>
///
public IAsyncEnumerable GetCertificateTypes() =>
_dbContext.CompanyCertificateTypes.AsNoTracking()
- .Select(certificate => new CompanyCertificateTypeData
+ .Where(type => type.CompanyCertificateTypeAssignedStatus!.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE)
+ .Select(type => new CompanyCertificateTypeData
(
- certificate.Id,
- certificate.CompanyCertificateTypeDescriptions
- .Where(y => y.CompanyCertificateType.CompanyCertificateTypeAssignedStatus.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE)
- .Select(x => new CertificateTypeDescription(x.LanguageShortName, x.Description))
+ type.Id,
+ type.CompanyCertificateTypeDescriptions
+ .Select(x => new CertificateTypeDescription(x.LanguageShortName, x.Description))
))
.AsAsyncEnumerable();
}
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
index 2c29495500..a078cb5bf3 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateStatus.cs
@@ -27,6 +27,7 @@ public class CompanyCertificateStatus
private CompanyCertificateStatus()
{
Label = null!;
+ CompanyCertificates = new HashSet();
}
public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId) : this()
@@ -39,4 +40,8 @@ public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId)
[MaxLength(255)]
public string Label { get; private set; }
+
+ // Navigation Properties
+
+ public virtual ICollection CompanyCertificates { get; private set; }
}
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
index 6ee4a2adc8..33678a1cfd 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateType.cs
@@ -28,6 +28,7 @@ private CompanyCertificateType()
{
Label = null!;
CompanyCertificates = new HashSet();
+ CompanyCertificateTypeDescriptions = new HashSet();
}
public CompanyCertificateType(CompanyCertificateTypeId companyCertificateTypeId) : this()
diff --git a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
index 89d958dbac..fab6127418 100644
--- a/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
+++ b/src/portalbackend/PortalBackend.PortalEntities/Entities/CompanyCertificateTypeStatus.cs
@@ -27,6 +27,7 @@ public class CompanyCertificateTypeStatus
private CompanyCertificateTypeStatus()
{
Label = null!;
+ CompanyCertificateTypeAssignedStatuses = new HashSet();
}
public CompanyCertificateTypeStatus(CompanyCertificateTypeStatusId companyCertificateTypeStatusId)
diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
index 25d6ff73a0..57bbbb926e 100644
--- a/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
+++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/StaticDataRepositoryTest.cs
@@ -21,6 +21,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests.Setup;
+using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Xunit.Extensions.AssemblyFixture;
@@ -171,6 +172,33 @@ public async Task GetCertificateTypes_ReturnsExpectedResult()
results.Should().HaveCount(12);
}
+ [Fact]
+ public async Task GetCertificateTypes_WithInactiveCertificateType_ReturnsExpectedResult()
+ {
+ // Arrange
+ var (context, sut) = await CreateSutWithContext().ConfigureAwait(false);
+ var active = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.ACTIVE);
+ var inactive = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.INACTVIE);
+ context.Remove(active);
+ context.Add(inactive);
+ await context.SaveChangesAsync().ConfigureAwait(false);
+
+ try
+ {
+ // Act
+ var results = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false);
+
+ // Assert
+ results.Should().HaveCount(11);
+ }
+ finally
+ {
+ context.Remove(inactive);
+ context.Add(active);
+ await context.SaveChangesAsync().ConfigureAwait(false);
+ }
+ }
+
#endregion
#region setup
@@ -182,5 +210,12 @@ private async Task CreateSut()
return sut;
}
+ private async Task<(PortalDbContext, StaticDataRepository)> CreateSutWithContext()
+ {
+ var context = await _dbTestDbFixture.GetPortalDbContext().ConfigureAwait(false);
+ var sut = new StaticDataRepository(context);
+ return (context, sut);
+ }
+
#endregion
}