summaryrefslogtreecommitdiff
path: root/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'Controllers')
-rw-r--r--Controllers/AuthorsController.cs14
-rw-r--r--Controllers/BooksController.cs19
2 files changed, 32 insertions, 1 deletions
diff --git a/Controllers/AuthorsController.cs b/Controllers/AuthorsController.cs
index 845708b..647a7e5 100644
--- a/Controllers/AuthorsController.cs
+++ b/Controllers/AuthorsController.cs
@@ -13,7 +13,7 @@ namespace LibraryAPI.Controllers {
}
[HttpGet]
- public async Task<ActionResult<IEnumerable<Author>>> getAuthors() {
+ public async Task<ActionResult<IEnumerable<Author>>> GetAuthors() {
if(_context.Authors == null) {
return NotFound();
}
@@ -34,6 +34,18 @@ namespace LibraryAPI.Controllers {
return author;
}
+ // Obtener los libros de un autor.
+ [HttpGet("{id}/books")]
+ public async Task<ActionResult<IEnumerable<Book>>> GetAuthorBooks(long id) {
+ return await _context.Books.Where(x => x.AuthorId == id).ToListAsync();
+ }
+
+ // Obtener primer objeto de la tabla.
+ [HttpGet("first")]
+ public async Task<ActionResult<Author>> GetFirst() {
+ return await _context.Authors.FirstOrDefaultAsync();
+ }
+
[HttpPut("{id}")]
public async Task<ActionResult> PutAuthor(long id, Author author) {
if(id != author.Id)
diff --git a/Controllers/BooksController.cs b/Controllers/BooksController.cs
index ad336f0..f46f2f0 100644
--- a/Controllers/BooksController.cs
+++ b/Controllers/BooksController.cs
@@ -12,11 +12,30 @@ namespace LibraryAPI.Controllers {
_context = context;
}
+ /* Listar todos los libros.
+ o, regresar el que tenga un título específico */
[HttpGet]
public async Task<ActionResult<IEnumerable<Book>>> GetBooks() {
return await _context.Books.ToListAsync();
}
+ // Obtener el primer libro de la tabla.
+ [HttpGet("first")]
+ public async Task<ActionResult<Book>> GetFirst() {
+ return await _context.Books.FirstOrDefaultAsync();
+ }
+
+ // Obtener un libro por isbn.
+ [HttpGet("{isbn}")]
+ public async Task<ActionResult<Book>> GetBook([FromRoute] string isbn) {
+ var book = await _context.Books.FirstOrDefaultAsync(x => x.ISBN == isbn);
+
+ if(book == null)
+ return NotFound();
+
+ return book;
+ }
+
[HttpGet("{id}")]
public async Task<ActionResult<Book>> GetBook(long id) {
if (_context.Books == null)