You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

3 years ago
using Microsoft.AspNetCore.Mvc;
using w21library.classes.Intf;
namespace w21library.Controllers
{
[ApiController]
[Route("/v1/library")]
public class LibraryControllerV1 : ControllerBase
{
private readonly ILibrary _library;
public LibraryControllerV1(ILibrary library)
{
_library = library;
}
[HttpGet("books")]
public IEnumerable<IBook> Get()
{
return _library.GetActiveBooks();
}
[HttpGet("books/{guid}")]
public IBook? Get(string guid)
{
return _library
.GetActiveBooks()
.FirstOrDefault(p => p.Uuid.Equals(guid));
}
[HttpDelete("books/{guid}")]
public void Delete(
// [FromQuery]
string guid)
{
bool result = _library.RemoveBook(guid);
Response.StatusCode = result
? 200
: 404;
}
[HttpPost("books")]
public bool Insert(
[FromForm] // [FromQuery]
string name,
[FromForm]
string author
)
{
return _library.AddBook(name, author);
}
}
}