More changes to the endpoint auto setup
This commit is contained in:
@@ -6,50 +6,31 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TOOHUCardAPI.Data;
|
||||
using TOOHUCardAPI.Models;
|
||||
|
||||
namespace TOOHUCardAPI.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PlayerDataController : ControllerBase
|
||||
public class PlayerDataController : MethodBasedController
|
||||
{
|
||||
private delegate Task<object> EndpointHandler(string requestBody);
|
||||
// Mapping of method => handler
|
||||
private Dictionary<string, EndpointHandler> registeredEndpointHandlers;
|
||||
|
||||
private void RegisterEndpointHandlers()
|
||||
{
|
||||
MethodInfo[] methods = typeof(PlayerDataController).GetMethods();
|
||||
registeredEndpointHandlers = methods
|
||||
.Aggregate(new Dictionary<string, EndpointHandler>(), (handlers, m) =>
|
||||
{
|
||||
Attribute attr = m.GetCustomAttribute(typeof(EndpointHandlerAttribute), false);
|
||||
if (attr != null)
|
||||
{
|
||||
EndpointHandlerAttribute e = (EndpointHandlerAttribute) attr;
|
||||
handlers.Add(e.Method, (EndpointHandler)m.CreateDelegate(typeof(EndpointHandler), this));
|
||||
}
|
||||
return handlers;
|
||||
});
|
||||
}
|
||||
|
||||
public PlayerDataController()
|
||||
{
|
||||
RegisterEndpointHandlers();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The game uses a single endpoint for player data.
|
||||
* The object they send has a method field that's used to decide what's being done
|
||||
* So let's use a single entry point and redirect based on that
|
||||
*/
|
||||
[HttpPost]
|
||||
public async Task<object> EntryPoint()
|
||||
public async Task<object> EntryPoint(IMethodBasedRequest methodRequest)
|
||||
{
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MissingEndpointHandlerException : Exception
|
||||
{
|
||||
public MissingEndpointHandlerException(string? method) : base($"Handler for [{method}] is either missing or incorrectly setup.")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user