AI Hints
Home›Spring Boot Tutorial›Project: The Plan, Entities, Repositories and Service
Spring Boot · Lesson 112 of 120

Project: The Plan

What we will build.

⏱ 2 min read▶ Video at 2:29:19🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Let's put everything together, into one complete project. A bookshop API, with a database, validation, clean errors, security, and tests. We'll build it step by step, one layer at a time.

  • One complete project
  • A bookshop API
  • One layer at a time

The endpoints

GET slash books lists the books, and can filter by author. GET with an id returns one book. POST adds a book. PUT on the price changes a price. And DELETE removes a book.

RequestDoes
GET /books?author=…list or search
GET /books/{id}one book
POST /booksadd a book
PUT /books/{id}/pricechange the price
DELETE /books/{id}remove a book

The layers

A request arrives at the controller. The controller checks the input, and calls the service. The service holds the business logic, inside transactions. The repository talks to the database. And DTOs carry the data back out, as JSON.

  1. Controller: HTTP + validation
  2. Service: logic + transactions
  3. Repository: queries
  4. H2 database
  5. DTOs → JSON

The rules

Anyone may read books. Logged in users may add books, and change prices. Only admins may delete. Bad input gets four hundred, and a missing book gets four oh four, both as problem details.

keyvalue
Readanyone
Add, change priceUSER or ADMIN
DeleteADMIN only
Errors400 / 404 as ProblemDetail

Summary

Our project is a layered bookshop API, with clear endpoints, and clear rules. Next, the entity, and the DTOs.

Key takeaways
  • 5 endpoints
  • 4 layers
  • Clear rules
Next up: Project: Entities — the data model