39 lines
925 B
C#
39 lines
925 B
C#
using GerbilManager.Models;
|
|
using GerbilManager.Repositories;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace GerbilManager.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("gerbils")]
|
|
public class GerbilsController : ControllerBase
|
|
{
|
|
private readonly IGerbilRepository repository;
|
|
|
|
public GerbilsController(IGerbilRepository repo)
|
|
{
|
|
this.repository = repo;
|
|
}
|
|
|
|
//GET /gerbils
|
|
[HttpGet]
|
|
public IEnumerable<Gerbil> GetGerbils()
|
|
{
|
|
var items = repository.GetGerbils();
|
|
return items;
|
|
}
|
|
|
|
//GET /gerbils
|
|
[HttpGet("{id}")]
|
|
public ActionResult<Gerbil> GetGerbil(Guid id)
|
|
{
|
|
var item = repository.GetGerbil(id);
|
|
|
|
if(item is null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return item;
|
|
}
|
|
}
|
|
} |