123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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<WorldController> logger;
- private readonly IConfiguration configuration;
- private JsonFileReader jsonFileReader;
- private JsonFileSaver jsonFileSaver;
- public WorldController(IConfiguration config, ILogger<WorldController> 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 = ""
- // };
- // }
- }
- }
|