BuecherwurmAPI/Controllers/KatalogController.cs

42 lines
1 KiB
C#
Raw Normal View History

2020-05-27 12:22:54 +00:00
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();
}
}
}