diff --git a/src/Artemis.Core/Services/WebServer/EndPoints/DataModelJsonPluginEndPoint.cs b/src/Artemis.Core/Services/WebServer/EndPoints/DataModelJsonPluginEndPoint.cs index 30532aa2b..052c9c5a3 100644 --- a/src/Artemis.Core/Services/WebServer/EndPoints/DataModelJsonPluginEndPoint.cs +++ b/src/Artemis.Core/Services/WebServer/EndPoints/DataModelJsonPluginEndPoint.cs @@ -15,9 +15,18 @@ namespace Artemis.Core.Services /// public class DataModelJsonPluginEndPoint : PluginEndPoint where T : DataModel { + private readonly ProfileModule? _profileModule; private readonly Module? _module; private readonly DataModelExpansion? _dataModelExpansion; + internal DataModelJsonPluginEndPoint(ProfileModule profileModule, string name, PluginsModule pluginsModule) : base(profileModule, name, pluginsModule) + { + _profileModule = profileModule ?? throw new ArgumentNullException(nameof(profileModule)); + + ThrowOnFail = true; + Accepts = MimeType.Json; + } + internal DataModelJsonPluginEndPoint(Module module, string name, PluginsModule pluginsModule) : base(module, name, pluginsModule) { _module = module ?? throw new ArgumentNullException(nameof(module)); @@ -54,7 +63,9 @@ namespace Artemis.Core.Services using TextReader reader = context.OpenRequestText(); try { - if (_module != null) + if (_profileModule != null) + JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _profileModule.DataModel); + else if (_module != null) JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _module.DataModel); else JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _dataModelExpansion!.DataModel); diff --git a/src/Artemis.Core/Services/WebServer/Interfaces/IWebServerService.cs b/src/Artemis.Core/Services/WebServer/Interfaces/IWebServerService.cs index ef98d3fa0..d88e3da3b 100644 --- a/src/Artemis.Core/Services/WebServer/Interfaces/IWebServerService.cs +++ b/src/Artemis.Core/Services/WebServer/Interfaces/IWebServerService.cs @@ -54,6 +54,15 @@ namespace Artemis.Core.Services /// The resulting end point DataModelJsonPluginEndPoint AddDataModelJsonEndPoint(Module module, string endPointName) where T : DataModel; + /// + /// Adds a new endpoint that directly maps received JSON to the data model of the provided . + /// + /// The data model type of the module + /// The module whose datamodel to apply the received JSON to + /// The name of the end point, must be unique + /// The resulting end point + DataModelJsonPluginEndPoint AddDataModelJsonEndPoint(ProfileModule profileModule, string endPointName) where T : DataModel; + /// /// Adds a new endpoint that directly maps received JSON to the data model of the provided . /// diff --git a/src/Artemis.Core/Services/WebServer/WebServerService.cs b/src/Artemis.Core/Services/WebServer/WebServerService.cs index 8de5ce9e4..d74035da2 100644 --- a/src/Artemis.Core/Services/WebServer/WebServerService.cs +++ b/src/Artemis.Core/Services/WebServer/WebServerService.cs @@ -136,6 +136,15 @@ namespace Artemis.Core.Services return endPoint; } + public DataModelJsonPluginEndPoint AddDataModelJsonEndPoint(ProfileModule profileModule, string endPointName) where T : DataModel + { + if (profileModule == null) throw new ArgumentNullException(nameof(profileModule)); + if (endPointName == null) throw new ArgumentNullException(nameof(endPointName)); + DataModelJsonPluginEndPoint endPoint = new(profileModule, endPointName, PluginsModule); + PluginsModule.AddPluginEndPoint(endPoint); + return endPoint; + } + public DataModelJsonPluginEndPoint AddDataModelJsonEndPoint(DataModelExpansion dataModelExpansion, string endPointName) where T : DataModel { if (dataModelExpansion == null) throw new ArgumentNullException(nameof(dataModelExpansion));