Skip to main content

Overview

The PrestamoService handles all operations related to book loans (préstamos) including requesting loans, listing loans, and managing loan approvals/rejections. It provides different methods for regular users and administrators. Location: src/app/core/services/prestamo.ts

Constructor

Uses Angular’s inject() function to obtain HttpClient instance.

Properties

string
default:"${environment.apiUrl}/prestamos"
Base URL for prestamo endpoints, configured from environment settings.

Methods

solicitar()

Requests a loan for a specific book. Available to authenticated users.
number
required
The unique identifier of the book to borrow
Returns: Observable<any> - Plain text response from server Response Type: Text (uses responseType: 'text') Example:
API Endpoint: POST ${apiUrl}/solicitar/{libroId} Request Body: Empty object {} Use Case: When a user wants to borrow a book from the catalog

getAll()

Retrieves all loan requests from all users. Admin-only endpoint.
Returns: Observable<Prestamo[]> - Array of all loan requests
array
Array of loan objects
number
Unique loan identifier
string
Date when the loan was requested (ISO 8601 format)
string
Date when the book was returned (if applicable)
string
Loan status: “PENDIENTE”, “APROBADO”, or “RECHAZADO”
Libro
Complete book object (id, titulo, portada, genero, autores, etc.)
any
User information from Spring Boot backend
Example:
API Endpoint: GET ${apiUrl}/todos Authorization: Requires ROLE_ADMIN

getMisPrestamos()

Retrieves loan requests for the currently authenticated user.
Returns: Observable<Prestamo[]> - Array of current user’s loan requests Example:
API Endpoint: GET ${apiUrl}/mios Authorization: Requires authentication (ROLE_USER or ROLE_ADMIN) Use Case: Displaying user’s loan history and current requests

aprobar()

Approves a pending loan request. Admin-only operation.
number
required
The unique identifier of the loan to approve
Returns: Observable<any> - Plain text response from server Response Type: Text (uses responseType: 'text') Example:
API Endpoint: POST ${apiUrl}/aprobar/{id} Request Body: Empty object {} Authorization: Requires ROLE_ADMIN Behavior: Changes loan status from PENDIENTE to APROBADO

rechazar()

Rejects a pending loan request. Admin-only operation.
number
required
The unique identifier of the loan to reject
Returns: Observable<any> - Plain text response from server Response Type: Text (uses responseType: 'text') Example:
API Endpoint: POST ${apiUrl}/rechazar/{id} Request Body: Empty object {} Authorization: Requires ROLE_ADMIN Behavior: Changes loan status from PENDIENTE to RECHAZADO

Complete Usage Examples

User Component (Request and View Loans)

Admin Component (Manage All Loans)

Data Model

Prestamo Interface

Estado (Status) Values

string
Loan request is awaiting admin approval
string
Loan has been approved by an administrator
string
Loan has been rejected by an administrator

Error Handling

Common error scenarios:

Authorization Requirements

See Also