WorldController.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Logging;
  5. using Microsoft.Extensions.Configuration;
  6. using gameapi.Library;
  7. namespace gameapi.Controllers
  8. {
  9. [ApiController]
  10. [Route("api/world")]
  11. [Produces("application/json")]
  12. public class WorldController : ControllerBase
  13. {
  14. private readonly ILogger<WorldController> logger;
  15. private readonly IConfiguration configuration;
  16. private JsonFileReader jsonFileReader;
  17. private JsonFileSaver jsonFileSaver;
  18. public WorldController(IConfiguration config, ILogger<WorldController> log)
  19. {
  20. configuration = config;
  21. logger = log;
  22. this.jsonFileReader = new JsonFileReader();
  23. this.jsonFileSaver = new JsonFileSaver();
  24. }
  25. [HttpGet]
  26. public IActionResult Get()
  27. {
  28. dynamic response = new
  29. {
  30. name = "World Get",
  31. code = StatusCodes.Status200OK,
  32. datetime = DateTime.Now
  33. };
  34. return Ok(response);
  35. }
  36. [HttpPost]
  37. public IActionResult HttpPost([FromBody] dynamic body)
  38. {
  39. dynamic response = new { code = StatusCodes.Status200OK, body = "" };
  40. // try
  41. // {
  42. // var typeProperty = body.GetProperty("type");
  43. // var type = typeProperty.ToString();
  44. // switch (type)
  45. // {
  46. // case "url_verification":
  47. // response = UrlVerification(body);
  48. // break;
  49. // case "event_callback":
  50. // response = EventCallback(body);
  51. // break;
  52. // default:
  53. // var bodyString = ((object)body).ToString();
  54. // logger.LogError($"Unknown Request Type: '{type}' = {bodyString}");
  55. // break;
  56. // }
  57. // }
  58. // catch (Exception e)
  59. // {
  60. // logger.LogError($"Event Error: '{e.Message}\n{e.StackTrace}'");
  61. // response = new
  62. // {
  63. // code = StatusCodes.Status405MethodNotAllowed,
  64. // body = ""
  65. // };
  66. // }
  67. return StatusCode(response.code, response);
  68. }
  69. // private dynamic UrlVerification(dynamic body)
  70. // {
  71. // var challenge = body.GetProperty("challenge");
  72. // var token = body.GetProperty("token");
  73. // //TODO: should save off the token?
  74. // logger.LogInformation($"Url Verification: Got Token: {token}");
  75. // return new
  76. // {
  77. // code = StatusCodes.Status200OK,
  78. // challenge = challenge,
  79. // body = ""
  80. // };
  81. // }
  82. }
  83. }