Multi-part Exercise: SmartCart: Build Your First Enterprise-Grade Product API #196
akash-coded
started this conversation in
Tasks
Replies: 5 comments
|
Here’s your downloadable base Spring Boot project template: This template includes:
Use this as the starting point for your next exercise. |
0 replies
🧠 Exercise: Build SmartCart - A Mini E-Commerce REST API🎯 ObjectiveYou will build a feature-complete Spring Boot REST API for managing a product catalog. You will learn:
🛠️ STEP 1: Project Setup
🧱 STEP 2: Define the Product Domain
🔹
|
0 replies
|
✅ Here is your complete SmartCart exercise bundle with guidelines, starter project, and Postman setup: 📦 smartcart-exercise-bundle.zip Inside you'll find:
|
0 replies
**
** |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🧠 Exercise Title: "SmartCart: Build Your First Enterprise-Grade Product API"
🗂️ Objective:
Design and implement a Spring Boot REST API for managing a shopping cart's product catalog with full CRUD operations, H2 database, request validation, DTO-layer, logging, caching, Swagger, and unit tests.
🧩 Step 0: Project Setup
🛠 Task:
Go to https://start.spring.io/
Add dependencies:
📁 Expected Project Structure:
🧾 Step 1: Define the Model
🔧 Create Entity:
Product.javawith fields:id: Longname: Stringdescription: Stringcategory: Stringprice: doublestockQty: int📌 Annotate with
@Entity,@Table, and@Id.📘 Use Lombok to reduce boilerplate:
💡 Step 2: DTOs & Validation
🔍 Create
ProductDTO.javawith same fields (but withoutidfor creation).🎯 Add validation:
@NotBlank,@Size,@Min,@NotNull, etc.🛡 Example:
🎯 Step 3: Repository Layer
🧱 Create
ProductRepository.java🔍 Step 4: Service Layer Interface & Impl
📌 Define
ProductServiceinterface:📌 Implement it in
ProductServiceImpl.javaUse:
ModelMapperfor DTO ↔ Entity conversion (or manual mapping)Slf4j)🌐 Step 5: Controller Layer
🎮 Create
ProductController.javaMap endpoints:
/api/products/api/products/{id}/api/products/api/products/{id}/api/products/{id}/api/products/category/api/products/valueUse:
@RequestParam,@PathVariable,@Valid@Operationfrom Swagger annotations🚨 Step 6: Error Handling
🛡 Add:
ProductNotFoundException extends RuntimeExceptionGlobalExceptionHandlerwith:@ExceptionHandler@ResponseStatus💾 Step 7: Seed Data
📁 Create
schema.sqlanddata.sql⚙️ Step 8: application.properties
📘 Step 9: Swagger + H2
http://localhost:8085/swagger-ui/index.htmlhttp://localhost:8085/h2-console📦 Step 10: Add Caching (Optional)
In
ProductServiceImpl:✅ Step 11: Add Unit Tests
@WebMvcTestfor controller testing@MockBeanMockMvcand test edge cases🧪 Postman Requests to Test
✅ Create:
❌ Edge Case:
💡 Bonus Challenges
/api/products?sort=price)Reviewentity and map it toProduct(OneToMany)All reactions