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();

        }
   }

}