Skip to content

About

BITS DB assignment

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book & Author Management System

A comprehensive Spring Boot application for managing books and authors with full CRUD operations, custom JPQL queries, and JSP-based UI.

🎯 Project Overview

This application demonstrates a complete Spring Boot implementation with:

  • Entity Management: Books and Authors with One-to-Many relationship
  • CRUD Operations: Create, Read, and Update operations for both entities
  • Custom Queries: INNER JOIN queries using JPQL
  • JSP Views: Beautiful, responsive UI with CSS styling
  • Exception Handling: Proper validation and error handling
  • Unit Testing: Comprehensive tests using JUnit and Mockito

📋 Features

Author Management

  • ✅ Create new authors with validation
  • ✅ View all authors in a list
  • ✅ View individual author details with their books
  • ✅ Update author information
  • ✅ Delete authors
  • ✅ Duplicate email detection

Book Management

  • ✅ Create new books with author association
  • ✅ View all books in a list
  • ✅ View individual book details with author information
  • ✅ Update book information
  • ✅ Delete books
  • ✅ Duplicate ISBN detection

Custom Query Features

  • ✅ INNER JOIN query to display books with author details
  • ✅ Filter books by author nationality
  • ✅ Filter books by genre with author details

🏗️ Entity Relationship Design

Author (1) -------- (N) Book

Author:
- id (PK)
- name
- email (unique)
- bio
- nationality

Book:
- id (PK)
- title
- isbn (unique)
- publicationYear
- price
- genre
- author_id (FK)

🛠️ Technology Stack

  • Framework: Spring Boot 3.1.5
  • Java: 17
  • Database: MySQL 8.0
  • ORM: Spring Data JPA (Hibernate)
  • View Layer: JSP with JSTL
  • Build Tool: Maven
  • Testing: JUnit 5, Mockito, AssertJ
  • Styling: CSS3
  • Validation: Jakarta Bean Validation

📁 Project Structure

book-author-management/
├── src/
│   ├── main/
│   │   ├── java/com/library/bookauthor/
│   │   │   ├── controller/          # MVC Controllers
│   │   │   │   ├── AuthorController.java
│   │   │   │   ├── BookController.java
│   │   │   │   └── HomeController.java
│   │   │   ├── entity/              # JPA Entities
│   │   │   │   ├── Author.java
│   │   │   │   └── Book.java
│   │   │   ├── repository/          # Data Access Layer
│   │   │   │   ├── AuthorRepository.java
│   │   │   │   └── BookRepository.java
│   │   │   ├── service/             # Business Logic
│   │   │   │   ├── AuthorService.java
│   │   │   │   └── BookService.java
│   │   │   ├── dto/                 # Data Transfer Objects
│   │   │   │   └── BookAuthorDTO.java
│   │   │   ├── exception/           # Custom Exceptions
│   │   │   │   ├── ResourceNotFoundException.java
│   │   │   │   └── DuplicateResourceException.java
│   │   │   └── BookAuthorManagementApplication.java
│   │   ├── resources/
│   │   │   ├── application.properties
│   │   │   ├── data.sql            # Sample data
│   │   │   └── static/css/
│   │   │       └── style.css
│   │   └── webapp/WEB-INF/views/   # JSP Views
│   │       ├── home.jsp
│   │       ├── author/
│   │       │   ├── list.jsp
│   │       │   ├── form.jsp
│   │       │   └── view.jsp
│   │       └── book/
│   │           ├── list.jsp
│   │           ├── form.jsp
│   │           ├── view.jsp
│   │           └── list-with-authors.jsp
│   └── test/                       # Unit Tests
│       └── java/com/library/bookauthor/
│           ├── repository/
│           │   ├── AuthorRepositoryTest.java
│           │   └── BookRepositoryTest.java
│           └── service/
│               ├── AuthorServiceTest.java
│               └── BookServiceTest.java
└── pom.xml

🚀 Getting Started

Prerequisites

  • Java 17 or higher
  • MySQL 8.0 or higher
  • Maven 3.6 or higher

Database Setup

  1. Create MySQL database:
CREATE DATABASE library_db;
  1. Update src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/library_db
spring.datasource.username=YOUR_USERNAME
spring.datasource.password=YOUR_PASSWORD

Running the Application

  1. Clone the repository
  2. Navigate to project directory
  3. Build the project:
mvn clean install
  1. Run the application:
mvn spring-boot:run
  1. Access the application:
http://localhost:8080

Running Tests

mvn test

📊 Sample Data

The application comes with 10 sample authors and 10 sample books pre-populated in the database through data.sql.

🎨 User Interface

The application features a modern, responsive design with:

  • Gradient headers
  • Card-based layouts
  • Hover effects and animations
  • Mobile-responsive tables
  • Color-coded buttons
  • Alert messages for user feedback

📝 API Endpoints

Authors

  • GET /authors - List all authors
  • GET /authors/new - Show create author form
  • POST /authors - Create new author
  • GET /authors/{id} - View author details
  • GET /authors/edit/{id} - Show edit author form
  • POST /authors/{id} - Update author
  • GET /authors/delete/{id} - Delete author

Books

  • GET /books - List all books
  • GET /books/with-authors - List books with authors (INNER JOIN)
  • GET /books/new - Show create book form
  • POST /books - Create new book
  • GET /books/{id} - View book details
  • GET /books/edit/{id} - Show edit book form
  • POST /books/{id} - Update book
  • GET /books/delete/{id} - Delete book

🔍 Custom Queries

INNER JOIN Query

@Query("SELECT new com.library.bookauthor.dto.BookAuthorDTO(" +
       "b.id, b.title, b.isbn, b.publicationYear, b.price, b.genre, " +
       "a.id, a.name, a.email, a.nationality) " +
       "FROM Book b INNER JOIN b.author a")
List<BookAuthorDTO> findAllBooksWithAuthors();

This query demonstrates:

  • JPQL INNER JOIN syntax
  • Constructor expression for DTO
  • Combining data from multiple entities
  • Type-safe query results

✅ Testing Coverage

  • Repository Layer: Tests for custom queries, CRUD operations
  • Service Layer: Business logic testing with Mockito
  • Test Types: Unit tests, integration tests
  • Assertions: Using AssertJ for fluent assertions

🐛 Exception Handling

  • ResourceNotFoundException: When entity is not found
  • DuplicateResourceException: For unique constraint violations
  • Form validation errors with user-friendly messages
  • Database integrity constraint handling

👨‍💻 Author

Created as a Spring Boot assignment demonstrating full-stack Java development skills.

📄 License

This project is created for educational purposes.

About

BITS DB assignment

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages