Created
June 8, 2020 10:52
-
-
Save NimzyMaina/2951fd59859cf47a6cc9038e0ec10e68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using TempConvert.Models; | |
using TempConvert.Interfaces; | |
using TempConvert.Repositories; | |
namespace TempConvert.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] | |
public class TempController : ControllerBase | |
{ | |
private readonly ITempConvertRepository _temp; | |
public TempController(ITempConvertRepository temp) | |
{ | |
_temp = temp; | |
} | |
[HttpPost("celsius")] | |
public async Task<IActionResult> Celsius(ConvertRequest model) | |
{ | |
var res = await _temp.FahrenheitToCelsiusAsync(model.Value); | |
return Ok(new | |
{ | |
Success = true, | |
Temp = $"{model.Value} degrees fahrenheit is == to {res} degrees celsius" | |
}); | |
} | |
[HttpPost("fahrenheit")] | |
public async Task<IActionResult> Fahrenheit(ConvertRequest model) | |
{ | |
var res = await _temp.CelsiusToFahrenheitAsync(model.Value); | |
return Ok(new | |
{ | |
Success = true, | |
Temp = $"{model.Value} degrees celsius is == to {res} degrees fahrenheit" | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment