Updated settings change route
This commit is contained in:
@@ -8,10 +8,10 @@ namespace DiscordBotCore.API.Endpoints;
|
||||
|
||||
internal sealed class EndpointManager
|
||||
{
|
||||
private WebApplication _appBuilder;
|
||||
private readonly WebApplication _AppBuilder;
|
||||
internal EndpointManager(WebApplication appBuilder)
|
||||
{
|
||||
_appBuilder = appBuilder;
|
||||
_AppBuilder = appBuilder;
|
||||
}
|
||||
|
||||
internal void MapEndpoint(IEndpoint endpoint)
|
||||
@@ -19,7 +19,7 @@ internal sealed class EndpointManager
|
||||
switch (endpoint.HttpMethod)
|
||||
{
|
||||
case EndpointType.Get:
|
||||
_appBuilder.MapGet(endpoint.Path, async context =>
|
||||
_AppBuilder.MapGet(endpoint.Path, async context =>
|
||||
{
|
||||
//convert the context to a string
|
||||
string jsonRequest = string.Empty;
|
||||
@@ -34,7 +34,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Put:
|
||||
_appBuilder.MapPut(endpoint.Path, async context =>
|
||||
_AppBuilder.MapPut(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
@@ -48,7 +48,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Post:
|
||||
_appBuilder.MapPost(endpoint.Path, async context =>
|
||||
_AppBuilder.MapPost(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
@@ -62,7 +62,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Delete:
|
||||
_appBuilder.MapDelete(endpoint.Path, async context =>
|
||||
_AppBuilder.MapDelete(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SettingsChangeEndpoint : IEndpoint
|
||||
return ApiResponse.Fail("Invalid json string");
|
||||
}
|
||||
|
||||
Dictionary<string, string> jsonDictionary = await JsonManager.ConvertFromJson<Dictionary<string, string>>(jsonRequest);
|
||||
Dictionary<string, object> jsonDictionary = await JsonManager.ConvertFromJson<Dictionary<string, object>>(jsonRequest);
|
||||
foreach (var (key, value) in jsonDictionary)
|
||||
{
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Set(key, value);
|
||||
|
||||
@@ -11,16 +11,11 @@ public class SettingsGetEndpoint : IEndpoint
|
||||
public EndpointType HttpMethod => EndpointType.Get;
|
||||
public async Task<ApiResponse> HandleRequest(string? jsonRequest)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonRequest))
|
||||
{
|
||||
return ApiResponse.Fail("The json from the request was empty");
|
||||
}
|
||||
|
||||
Dictionary<string, object> jsonSettingsDictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"token", Application.CurrentApplication.ApplicationEnvironmentVariables.Get("token", string.Empty)},
|
||||
{"prefix", Application.CurrentApplication.ApplicationEnvironmentVariables.Get("prefix", string.Empty)},
|
||||
{"ServerIDs", Application.CurrentApplication.ApplicationEnvironmentVariables.GetList("ServerIDs", new List<ulong>())}
|
||||
{"serverIds", Application.CurrentApplication.ApplicationEnvironmentVariables.GetList("ServerID", new List<ulong>())}
|
||||
};
|
||||
|
||||
string jsonResponse = await JsonManager.ConvertToJsonString(jsonSettingsDictionary);
|
||||
|
||||
Reference in New Issue
Block a user