I received this document for creating FizzBuzz small application and I need some guide through above steps for doing API FizzBuzz
ProgrammingSteps:
- Createa .net 6 API applicationwith a FizzBuzz controller
- APIshouldcontain a swagger interface for testing.
- CreateaFizzBuzzServicethatwillprocesstheFizzBuzzsolution.
- Bonus:Avoidusing"ifelse".
- Serviceshould beabletologresults.
- Bonus:Usethe.netILoggerinterface
- InjecttheFizzBuzzServiceintotheFizzBuzzcontroller.
- Add a Get method calltothe FizzBuzz controller that returns a result listof theFizzBuzz solution for numbers 1-50.
- Bonus:UseaLINQstatementtoonlyreturnvaluesthatcontainavalidstring
- Add a secondGet method callto theFizzBuzz controller that passes aninteger value andreturns the FizzBuzz solution for that value.
- Example; a value of15should return "FizzBuzz"and a value of 2should returnan empty string.
- Bonus:Ifvalueisgreaterthan50returnBadRequestcode.
Code below:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Project23.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class FizzBuzzController : ControllerBase
{
[HttpGet]
public string FizzBuzz([FromQuery] int n)
{
if (n % 15 == 0)
{
return "FizzBuzz";
}
else if (n % 5 == 0)
{
return "Buzz";
}
else if (n % 3 == 0)
{
return "Fizz";
}
else
{
return n.ToString();
}
}
}
}
Any directions to create and develop API FizzBuzz and controllers using Visual Studio 2019/2022 will be appreciated.
Thanks.