mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Web Server - Added ProfileModule override to DataModelJsonPluginEndPoint
This commit is contained in:
parent
b209bfd833
commit
94fac36ffe
@ -15,9 +15,18 @@ namespace Artemis.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataModelJsonPluginEndPoint<T> : PluginEndPoint where T : DataModel
|
public class DataModelJsonPluginEndPoint<T> : PluginEndPoint where T : DataModel
|
||||||
{
|
{
|
||||||
|
private readonly ProfileModule<T>? _profileModule;
|
||||||
private readonly Module<T>? _module;
|
private readonly Module<T>? _module;
|
||||||
private readonly DataModelExpansion<T>? _dataModelExpansion;
|
private readonly DataModelExpansion<T>? _dataModelExpansion;
|
||||||
|
|
||||||
|
internal DataModelJsonPluginEndPoint(ProfileModule<T> profileModule, string name, PluginsModule pluginsModule) : base(profileModule, name, pluginsModule)
|
||||||
|
{
|
||||||
|
_profileModule = profileModule ?? throw new ArgumentNullException(nameof(profileModule));
|
||||||
|
|
||||||
|
ThrowOnFail = true;
|
||||||
|
Accepts = MimeType.Json;
|
||||||
|
}
|
||||||
|
|
||||||
internal DataModelJsonPluginEndPoint(Module<T> module, string name, PluginsModule pluginsModule) : base(module, name, pluginsModule)
|
internal DataModelJsonPluginEndPoint(Module<T> module, string name, PluginsModule pluginsModule) : base(module, name, pluginsModule)
|
||||||
{
|
{
|
||||||
_module = module ?? throw new ArgumentNullException(nameof(module));
|
_module = module ?? throw new ArgumentNullException(nameof(module));
|
||||||
@ -54,7 +63,9 @@ namespace Artemis.Core.Services
|
|||||||
using TextReader reader = context.OpenRequestText();
|
using TextReader reader = context.OpenRequestText();
|
||||||
try
|
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);
|
JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _module.DataModel);
|
||||||
else
|
else
|
||||||
JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _dataModelExpansion!.DataModel);
|
JsonConvert.PopulateObject(await reader.ReadToEndAsync(), _dataModelExpansion!.DataModel);
|
||||||
|
|||||||
@ -54,6 +54,15 @@ namespace Artemis.Core.Services
|
|||||||
/// <returns>The resulting end point</returns>
|
/// <returns>The resulting end point</returns>
|
||||||
DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(Module<T> module, string endPointName) where T : DataModel;
|
DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(Module<T> module, string endPointName) where T : DataModel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a new endpoint that directly maps received JSON to the data model of the provided <paramref name="profileModule" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The data model type of the module</typeparam>
|
||||||
|
/// <param name="profileModule">The module whose datamodel to apply the received JSON to</param>
|
||||||
|
/// <param name="endPointName">The name of the end point, must be unique</param>
|
||||||
|
/// <returns>The resulting end point</returns>
|
||||||
|
DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(ProfileModule<T> profileModule, string endPointName) where T : DataModel;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new endpoint that directly maps received JSON to the data model of the provided <paramref name="dataModelExpansion" />.
|
/// Adds a new endpoint that directly maps received JSON to the data model of the provided <paramref name="dataModelExpansion" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -136,6 +136,15 @@ namespace Artemis.Core.Services
|
|||||||
return endPoint;
|
return endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(ProfileModule<T> profileModule, string endPointName) where T : DataModel
|
||||||
|
{
|
||||||
|
if (profileModule == null) throw new ArgumentNullException(nameof(profileModule));
|
||||||
|
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
|
||||||
|
DataModelJsonPluginEndPoint<T> endPoint = new(profileModule, endPointName, PluginsModule);
|
||||||
|
PluginsModule.AddPluginEndPoint(endPoint);
|
||||||
|
return endPoint;
|
||||||
|
}
|
||||||
|
|
||||||
public DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(DataModelExpansion<T> dataModelExpansion, string endPointName) where T : DataModel
|
public DataModelJsonPluginEndPoint<T> AddDataModelJsonEndPoint<T>(DataModelExpansion<T> dataModelExpansion, string endPointName) where T : DataModel
|
||||||
{
|
{
|
||||||
if (dataModelExpansion == null) throw new ArgumentNullException(nameof(dataModelExpansion));
|
if (dataModelExpansion == null) throw new ArgumentNullException(nameof(dataModelExpansion));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user