From 766d9635dc09886707213cdbafa8a783a143ce84 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Tue, 20 Sep 2022 20:21:39 -0500 Subject: Añadidas más rutas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/BooksController.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Controllers/BooksController.cs') 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>> GetBooks() { return await _context.Books.ToListAsync(); } + // Obtener el primer libro de la tabla. + [HttpGet("first")] + public async Task> GetFirst() { + return await _context.Books.FirstOrDefaultAsync(); + } + + // Obtener un libro por isbn. + [HttpGet("{isbn}")] + public async Task> 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> GetBook(long id) { if (_context.Books == null) -- cgit v1.2.3