Skip to content

Commit

Permalink
feat: introduce enums for API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
romanett committed Nov 9, 2023
1 parent 52aacb7 commit 60aeec1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion GDSwithREST/Controllers/ApplicationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task<ActionResult<ApplicationApiModel>> RegisterApplication([FromBo
{
ApplicationId = applicationRaw.ApplicationId,
ApplicationUri = applicationRaw.ApplicationUri,
ApplicationType = (ApplicationType)applicationRaw.ApplicationType,
ApplicationType = (Opc.Ua.ApplicationType)applicationRaw.ApplicationType,
ApplicationNames = applicationName,
ProductUri = applicationRaw.ProductUri
};
Expand Down
23 changes: 19 additions & 4 deletions GDSwithREST/Data/Models/ApiModels/ApplicationApiModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Cryptography.X509Certificates;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json.Serialization;

namespace GDSwithREST.Data.Models.ApiModels
Expand All @@ -20,7 +21,7 @@ public class ApplicationApiModel
/// The name of the Application
/// </summary>
public string ApplicationName { get; set; } = null!;
public int ApplicationType { get; set; }
public ApplicationType ApplicationType { get; set; }
public string ProductUri { get; set; } = null!;
/// <summary>
/// The gds signed certificate of the Application
Expand All @@ -34,7 +35,7 @@ public ApplicationApiModel(Applications application)
ApplicationUri = application.ApplicationUri;
ApplicationName = application.ApplicationName;
ProductUri = application.ProductUri;
ApplicationType = application.ApplicationType;
ApplicationType = (ApplicationType)application.ApplicationType;
if(application.Certificate.Length > 0)
Certificate = new X509CertificateApiModel(new X509Certificate2(application.Certificate));
}
Expand All @@ -44,8 +45,22 @@ public ApplicationApiModel(Guid applicationId, string applicationUri, string app
ApplicationId = applicationId;
ApplicationUri = applicationUri;
ApplicationName = applicationName;
ApplicationType = applicationType;
ApplicationType = (ApplicationType)applicationType;
ProductUri = productUri;
}
}
/// <summary>
/// Type of the registered OPC UA Application
/// </summary>
public enum ApplicationType
{
[EnumMember(Value = "Server_0")]
Server,
[EnumMember(Value = "Client_1")]
Client,
[EnumMember(Value = "ClientAndServer_2")]
ClientAndServer,
[EnumMember(Value = "DiscoveryServer_3")]
DiscoveryServer
}
}
23 changes: 18 additions & 5 deletions GDSwithREST/Data/Models/ApiModels/CertificateGroupApiModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Security.Cryptography.X509Certificates;
using System.Configuration;
using GDSwithREST.Services.GdsBackgroundService.Databases;
using System.Runtime.Serialization;

namespace GDSwithREST.Data.Models.ApiModels
{
Expand All @@ -15,7 +16,7 @@ public CertificateGroupApiModel(CertificateGroup certificateGroup)
{
try
{
Id = (uint)certificateGroup.Id.Identifier;
Id = (CertificateGroupType)(uint)certificateGroup.Id.Identifier;
UpdateRequired = certificateGroup.UpdateRequired;
Ceritificate = new X509CertificateApiModel(certificateGroup.Certificate);
}
Expand All @@ -27,7 +28,7 @@ public CertificateGroupApiModel(uint id, X509Certificate2 certificate, bool upda
{
try
{
Id = id;
Id = (CertificateGroupType)id;
UpdateRequired = updateRequired;
Ceritificate = new X509CertificateApiModel(certificate);
}
Expand All @@ -36,9 +37,21 @@ public CertificateGroupApiModel(uint id, X509Certificate2 certificate, bool upda
}
}

public uint Id { get; set; }
public CertificateGroupType Id { get; set; }
public bool UpdateRequired { get; set; }
public X509CertificateApiModel? Ceritificate { get; set; }

public X509CertificateApiModel? Ceritificate { get; set; }
}

/// <summary>
/// Type of the Certificate Group
/// </summary>
public enum CertificateGroupType
{
[EnumMember(Value = "DefaultApplicationGroup_615")]
DefaultApplicationGroup = 615,
[EnumMember(Value = "DefaultHttpsGroup_649")]
DefaultHttpsGroup = 649,
[EnumMember(Value = "DefaultUserTokenGroup_683")]
DefaultUserTokenGroup = 683,
}
}

0 comments on commit 60aeec1

Please sign in to comment.