using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using gameapi.Library; namespace gameapi.Controllers { [ApiController] [Route("api/world")] [Produces("application/json")] public class WorldController : ControllerBase { private readonly ILogger logger; private readonly IConfiguration configuration; private JsonFileReader jsonFileReader; private JsonFileSaver jsonFileSaver; public WorldController(IConfiguration config, ILogger log) { configuration = config; logger = log; this.jsonFileReader = new JsonFileReader(); this.jsonFileSaver = new JsonFileSaver(); } [HttpGet] public IActionResult Get() { dynamic response = new { name = "World Get", code = StatusCodes.Status200OK, datetime = DateTime.Now }; return Ok(response); } [HttpPost] public IActionResult HttpPost([FromBody] dynamic body) { dynamic response = new { code = StatusCodes.Status200OK, body = "" }; // try // { // var typeProperty = body.GetProperty("type"); // var type = typeProperty.ToString(); // switch (type) // { // case "url_verification": // response = UrlVerification(body); // break; // case "event_callback": // response = EventCallback(body); // break; // default: // var bodyString = ((object)body).ToString(); // logger.LogError($"Unknown Request Type: '{type}' = {bodyString}"); // break; // } // } // catch (Exception e) // { // logger.LogError($"Event Error: '{e.Message}\n{e.StackTrace}'"); // response = new // { // code = StatusCodes.Status405MethodNotAllowed, // body = "" // }; // } return StatusCode(response.code, response); } // private dynamic UrlVerification(dynamic body) // { // var challenge = body.GetProperty("challenge"); // var token = body.GetProperty("token"); // //TODO: should save off the token? // logger.LogInformation($"Url Verification: Got Token: {token}"); // return new // { // code = StatusCodes.Status200OK, // challenge = challenge, // body = "" // }; // } } }