https://github.com/techkumarnitish/book-read-spring-boot-complete
https://github.com/techkumarnitish/book-read-spring-boot-complete
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/techkumarnitish/book-read-spring-boot-complete
- Owner: TechKumarNitish
- Created: 2025-05-17T05:59:32.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-10T16:22:31.000Z (9 months ago)
- Last Synced: 2025-08-10T18:13:43.944Z (9 months ago)
- Language: Java
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Goodreads Clone – Spring Boot REST API
A simple **Spring Boot**-based REST API for managing books, authors, and publishers, inspired by Goodreads.
Implements full CRUD operations with proper relational mappings using **Spring Data JPA** and **Hibernate**.Also robust JWT-based authentication & authorization.
---
## Features
* **Books**: Add, update, delete, view books with linked authors and publishers.
* **Authors**: Manage authors and associate them with multiple books.
* **Publishers**: Manage publishers and associate them with books.
* **Relations**:
* `Book` ↔ `Author`: Many-to-Many
* `Book` ↔ `Publisher`: Many-to-One
* Input validation with HTTP status codes (`404`, `400`, `204`).
* JPA repositories for database interaction.
* Clear separation of **Model**, **Repository**, and **Service** layers.
---
## Tech Stack
* **Java 11+**
* **Spring Boot**
* **Spring Data JPA**
* **Hibernate**
* **H2 / MySQL** (configurable)
* **Jackson** for JSON serialization
---
## Project Structure
```
src/main/java/com/example/goodreads/
│
├── controller/
│ ├── AuthorController.java
│ ├── BookController.java
│ ├── PublisherController.java
│ └── AuthController.java # Register/Login endpoints issuing JWT tokens
│
├── model/
│ ├── Author.java
│ ├── Book.java
│ ├── Publisher.java
│ └── User.java # User entity for authentication
│
├── repository/
│ ├── AuthorRepository.java / AuthorJpaRepository.java
│ ├── BookRepository.java / BookJpaRepository.java
│ ├── PublisherRepository.java / PublisherJpaRepository.java
│ └── UserRepository.java # JPA repository for User
│
├── service/
│ ├── AuthorJpaService.java
│ ├── BookJpaService.java
│ ├── PublisherJpaService.java
│ └── UserService.java (optional) # User management & authentication logic
│
├── security/
│ ├── JwtFilter.java # Filters requests, validates JWT
│ ├── JwtUtils.java # Generates and validates JWT tokens
│ └── SecurityConfig.java # Spring Security config and filter chain
│
└── Application.java # Main Spring Boot starter class
```
---
## API Endpoints (Examples)
### **Books**
```
GET /books → Get all books
GET /books/{id} → Get book by ID
POST /books → Add new book
PUT /books/{id} → Update book
DELETE /books/{id} → Delete book
GET /books/{id}/authors → Get authors of a book
GET /books/{id}/publisher→ Get publisher of a book
```
### **Authors**
```
GET /authors
GET /authors/{id}
POST /authors
PUT /authors/{id}
DELETE /authors/{id}
```
### **Publishers**
```
GET /publishers
GET /publishers/{id}
POST /publishers
PUT /publishers/{id}
DELETE /publishers/{id}
```
---
## Setup & Run
1. **Clone repository**
```bash
git clone
cd goodreads
```
2. **Configure DB** in `src/main/resources/application.properties`:
```properties
spring.datasource.url=jdbc:h2:mem:goodreads
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
```
3. **Build & Run**
```bash
mvn spring-boot:run
```
4. **Access API**
```
http://localhost:8080
```
5. **H2 Console** (if enabled)
```
http://localhost:8080/h2-console
```
---
## Notes
* **Error Handling**: Returns `404` when resource not found, `400` for invalid input, and `204` for successful deletion without content.
* **Entity Relationships**: Managed using `@ManyToOne`, `@ManyToMany`, and join tables for author–book mapping.
* **Extensibility**: New fields and relations can be added easily by extending models and repositories.
---