This project is a Library Management System API built using Spring Boot. The system allows librarians to manage books, patrons, and borrowing records.
- Attributes:
id(Long): Unique identifier for the book.title(String): Title of the book.author(String): Author of the book.publicationYear(Integer): Year the book was published.isbn(String): ISBN of the book.- Other relevant attributes.
- Attributes:
id(Long): Unique identifier for the patron.name(String): Name of the patron.contactInfo(String): Contact information of the patron.- Other relevant attributes.
- Attributes:
id(Long): Unique identifier for the borrowing record.bookId(Long): ID of the borrowed book.patronId(Long): ID of the patron who borrowed the book.borrowDate(LocalDate): Date when the book was borrowed.returnDate(LocalDate): Date when the book was returned (if returned).
- Attributes:
id(Long): Unique identifier for the user.username(String): Username of the user.password(String): Encrypted password of the user.role(Role): Role of the user (e.g., USER, ADMIN).
- Values:
USERADMIN
- GET /api/books: Retrieve a list of all books.
- GET /api/books/{id}: Retrieve details of a specific book by ID.
- POST /api/books: Add a new book to the library.
- PUT /api/books/{id}: Update an existing book's information.
- DELETE /api/books/{id}: Remove a book from the library.
- GET /api/patrons: Retrieve a list of all patrons.
- GET /api/patrons/{id}: Retrieve details of a specific patron by ID.
- POST /api/patrons: Add a new patron to the system.
- PUT /api/patrons/{id}: Update an existing patron's information.
- DELETE /api/patrons/{id}: Remove a patron from the system.
- POST /api/borrow/{bookId}/patron/{patronId}: Allow a patron to borrow a book.
- PUT /api/return/{bookId}/patron/{patronId}: Record the return of a borrowed book by a patron.
- POST /api/auth/register: Register a new user.
- POST /api/auth/login: Authenticate a user and return a JWT.
- PostgreSQL is used to persist book, patron, and borrowing record details.
- Proper relationships are set up between entities, such as one-to-many between books and borrowing records.
- Input validation is implemented for API requests, validating required fields and data formats.
- Exceptions are handled gracefully, returning appropriate HTTP status codes and error messages.
- JWT-based authorization is implemented to protect the API endpoints.
- Declarative transaction management is implemented using Spring's
@Transactionalannotation to ensure data integrity during critical operations.
- Unit tests are written to validate the functionality of API endpoints.
- Testing frameworks like JUnit, Mockito, and SpringBootTest are used for testing.
Located in the config folder, this contains configurations for the application and security, including JWT services.
Located in the user folder, this contains:
- User Entity: Defines the user attributes and relationships.
- Role Enum: Defines the roles available in the system.
- Auth: Contains registration and login services.
- Java 11 or higher
- Maven
- PostgreSQL
-
Clone the repository:
git clone https://github.com/monasr6/Library-System-Spring cd Library-System-Spring -
Configure the database in
src/main/resources/application.properties:spring.datasource.url=jdbc:postgresql://localhost:5433/libsystemspring spring.datasource.username=postgres spring.datasource.password=postgres spring.jpa.hibernate.ddl-auto=update
-
Build and run the application:
mvn clean install mvn spring-boot:run
-
Use tools like Postman or curl to interact with the API endpoints.
-
For example, to add a new book:
curl -X POST -H "Content-Type: application/json" -d '{"title":"Book Title","author":"Author Name","publicationYear":2021,"isbn":"1234567890123"}' http://localhost:8080/api/books
-
Run the unit tests using Maven:
mvn test
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
This documentation provides an overview of the project, outlines the requirements, and gives instructions on how to set up and use the Library Management System API.