12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- namespace jsonapi.Controllers
- {
- [ApiController]
- [Route("")]
- [Produces("application/json")]
- public class IndexController : ControllerBase
- {
- private Library.SHA256HashGenerator sha256HashGenerator;
- private Library.JsonFileReader jsonFileReader;
- public IndexController()
- {
- sha256HashGenerator = Library.SHA256HashGenerator.GetInstance();
- jsonFileReader = Library.JsonFileReader.GetInstance();
- }
- [HttpGet]
- public IActionResult Get()
- {
- try
- {
- var json = jsonFileReader.Read("Static/index.json");
- return Ok(json);
- }
- catch (Exception)
- {
- dynamic errorObject = new
- {
- errorCode = StatusCodes.Status500InternalServerError,
- errorMessage = "500 Error: Something went wrong. Please contact the administrator for assistance."
- };
- return StatusCode(errorObject.errorCode, errorObject);
- }
- }
- [HttpGet("hash/{key}")]
- public IActionResult GetHash(string key)
- {
- return Ok(sha256HashGenerator.Get(key));
- }
- }
- }
|