-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIntegerToRomanNumeralsFunctionApp.cs
More file actions
41 lines (37 loc) · 1.79 KB
/
IntegerToRomanNumeralsFunctionApp.cs
File metadata and controls
41 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace DotnetGuildTraining;
public class IntegerToRomanNumeralsFunctionApp
{
private readonly ILogger<IntegerToRomanNumeralsFunctionApp> _logger;
private readonly int[] intVals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
private readonly string[] symbols = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
public IntegerToRomanNumeralsFunctionApp(ILogger<IntegerToRomanNumeralsFunctionApp> logger)
{
_logger = logger;
}
/// <summary>
/// Implement this function to return the roman numeral representation of a provided number.
/// Assume the number to be between 0 and 4000, if it is outside this region, return a bad request (400) response.
/// This is quite a tricky exercise. You can find a tip here: https://www.mathsisfun.com/roman-numerals.html
/// </summary>
/// <param name="req">The HTTP request for the Function App call</param>
/// <param name="number">The integer to be converted to roman numerals</param>
/// <returns></returns>
[Function("IntegerToRomanNumeralsFunctionApp")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "integer-to-roman/{number:int}")] HttpRequest req, int number)
{
try
{
_logger.LogInformation($"Started {nameof(IntegerToRomanNumeralsFunctionApp)}");
return new OkObjectResult("OK");
}
catch (Exception e)
{
_logger.LogError($"Error at {nameof(IntegerToRomanNumeralsFunctionApp)}: {e}");
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
}
}
}