Skip to content

Commit

Permalink
feat: se agrega la interfaz del servicio(IFibonacciServicios), el ser…
Browse files Browse the repository at this point in the history
…vicio(FibonacciServicios), el controller(FibonacciController).

Esto permite calcular la serie de Fibonacci, de un numero perteneciente al conjunto de los Naturales entre 0 y 90.

Issues: #4, #5 y #12
  • Loading branch information
Romina Fernandez committed Dec 2, 2019
1 parent 3ed69c4 commit c54d87f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/FibonacciWebApi/Controllers/FibonacciController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FibonacciWebApi.Servicios;

namespace FibonacciWebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FibonacciController : ControllerBase
{
[HttpGet]
public ActionResult<string> Get()
{
return "Debe ingresar un numero para realizar Fibonacci";
}

[HttpGet("{numero}")]
public ActionResult<string> Get(int numero)
{
IFibonacciServicios f = new FibonacciServicios();
if (numero < 0 || numero > 90)
{
return "Debe ingresar un numero perteneciente al conjunto de los Naturales entre 0 y 90";
}
else
{
return f.CalcularFibonacci(numero).ToString();
}
//return RealizarFibonacci(fibo);
}

//private int RealizarFibonacci(int fibo)
//{
// if (fibo == 0)
// {
// return 0;
// }
// else if (fibo == 1)
// {
// return 1;
// }
// else
// {
// return RealizarFibonacci(fibo - 1) + RealizarFibonacci(fibo - 2);
// }
//}
}
}
31 changes: 31 additions & 0 deletions src/FibonacciWebApi/Servicios/FibonacciServicios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace FibonacciWebApi.Servicios
{
public class FibonacciServicios : IFibonacciServicios
{
public int CalcularFibonacci(int i)
{
return RealizarFibonacci(i);
}

public int RealizarFibonacci(int fibo)
{ if (fibo == 0)
{
return 0;
}
else if (fibo == 1)
{
return 1;
}
else
{
return RealizarFibonacci(fibo - 1) + RealizarFibonacci(fibo - 2);
}
}
}
}
12 changes: 12 additions & 0 deletions src/FibonacciWebApi/Servicios/IFibonacciServicios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FibonacciWebApi.Servicios
{
public interface IFibonacciServicios
{
int CalcularFibonacci(int i);
}
}

0 comments on commit c54d87f

Please sign in to comment.