IndexController.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. namespace jsonapi.Controllers
  5. {
  6. [ApiController]
  7. [Route("")]
  8. [Produces("application/json")]
  9. public class IndexController : ControllerBase
  10. {
  11. private Library.SHA256HashGenerator sha256HashGenerator;
  12. private Library.JsonFileReader jsonFileReader;
  13. public IndexController()
  14. {
  15. sha256HashGenerator = Library.SHA256HashGenerator.GetInstance();
  16. jsonFileReader = Library.JsonFileReader.GetInstance();
  17. }
  18. [HttpGet]
  19. public IActionResult Get()
  20. {
  21. try
  22. {
  23. var json = jsonFileReader.Read("Static/index.json");
  24. return Ok(json);
  25. }
  26. catch (Exception)
  27. {
  28. dynamic errorObject = new
  29. {
  30. errorCode = StatusCodes.Status500InternalServerError,
  31. errorMessage = "500 Error: Something went wrong. Please contact the administrator for assistance."
  32. };
  33. return StatusCode(errorObject.errorCode, errorObject);
  34. }
  35. }
  36. [HttpGet("hash/{key}")]
  37. public IActionResult GetHash(string key)
  38. {
  39. return Ok(sha256HashGenerator.Get(key));
  40. }
  41. }
  42. }