BuecherwurmAPI/Controllers/KatalogController.cs
2020-05-27 14:22:54 +02:00

42 lines
No EOL
1 KiB
C#

using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using BuecherwurmAPI.Data;
namespace BuecherwurmAPI.Controllers
{
[Route("katalog") ]
[ApiController]
public class KatalogController :ControllerBase
{
private readonly IBookRepo _repository;
public KatalogController (IBookRepo repository)
{
_repository=repository;
}
// GET Katalog
[HttpGet]
public ActionResult<IEnumerable<Book>> GetAllBooks()
{
var books =_repository.GetAllBooks();
return Ok(books);
}
// GET Katalog/{id}
[HttpGet("{id}", Name ="GetBookByID")]
public ActionResult <IEnumerable<Book>> GetBookByID(int id)
{
var bookItem = _repository.GetBookById(id);
if (bookItem != null)
{
return Ok(bookItem);
}
return NoContent();
}
}
}