Skip to main content

Overview

The CatalogoComponent displays the complete catalog of available books to regular users. It allows users to browse books and request loans for available titles.

Component Metadata

Selector: app-catalogo Imports:
  • CommonModule - Angular common directives
Template: ./catalogo.html

Properties

libros

Array containing all books fetched from the backend. Each book includes:
  • id: Book identifier
  • titulo: Book title
  • portada: Cover image URL
  • anioPublicacion: Publication year
  • disponible: Availability status
  • genero: Genre information
  • autores: Array of author information

loading

Indicates whether the book data is currently being loaded. Used to show loading spinner.

Injected Services

  • LibroService - Fetches book data from the API
  • PrestamoService - Handles loan requests

Lifecycle Hooks

ngOnInit

Called on component initialization. Loads all books from the backend.

Methods

cargarLibros

Fetches all books from the LibroService:
  • On success: Populates libros array and sets loading to false
  • On error: Logs error to console and sets loading to false

solicitarPrestamo

Initiates a loan request for the specified book:
  1. Displays confirmation dialog with book title
  2. If confirmed, calls PrestamoService.solicitar() with the book ID
  3. On success: Shows success alert informing user that admin will review the request
  4. On error: Shows error alert with the error message from the backend
Parameters:
  • libro - The Libro object for which to request a loan

Template Features

The component template displays books in a responsive card grid:

Full Source Code

  • Libro - Book data structure