Spring Boot - n-Tier Architecture - π§ͺ Guided Exercise: BurgerByte v2 β Refactor for Scalability #189
akash-coded
started this conversation in
Tasks
Replies: 3 comments
-
**
** |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
PRASETHA N |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
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.
-
π§ͺ Guided Exercise: BurgerByte v2 β Refactor for Scalability
π§ Core Learning Objectives:
π§© Phase 1: Quick & Dirty API (Just Controller + Model)
Ask them to create this βnaiveβ version that handles everything inside the controller.
π The Feature:
Model:
BurgerController:
BurgerControllerCRUD endpoints:
GET /api/burgersβ list allPOST /api/burgersβ add newGET /api/burgers?id=1β get oneDELETE /api/burgers?id=1β delete oneUse an internal
List<Burger>inside the controller.π€― Discussion Prompt:
After they build it:
π£ βWhat if we need to reuse this burger-fetching logic in another controller?β
π£ βHow do we unit test the logic without spinning up Spring Boot?β
π£ βWhat if we now add multiple resources (Drinks, Combos)? Will we copy-paste logic?β
π£ βWhat if the logic for computing price gets longer?β
π£ βWhat if a new developer has to debug your controller?β
π Phase 2: Refactor Using a
BurgerServiceNow guide them to extract all business logic into a separate service class.
β Folder Structure (explain it)
π§± Model Class
π§ Phase-2 Starter Task
Split logic:
BurgerServicemanages theList<Burger>and all add/delete/get/search logicBurgerControllerjust routes to the serviceπ‘ Provide Partial Templates
π§ BurgerService.java (fill in the blanks)
πΉοΈ BurgerController.java
π§ Developer Nugget: WHY Service Layer?
π§Ή Separation of Concerns
Keep controller thin. Avoid bloated
@RestControllers.π Reusability
Other controllers or scheduled jobs can reuse
BurgerService.π§ͺ Testability
Easily mock
BurgerServicefor unit testing.π Pluggability
In future, weβll plug JPA repository instead of in-memory list without touching controller.
π§ͺ Bonus Challenge: Add Business Logic in Service
burger.price < 50, reject burger as "Too cheap for Mars!"getAffordableBurgers(double maxPrice)/api/burgers/search?name=cheez(partial match)π§Ύ Deliverables
Burger.java(Model)BurgerController.java(Routing only)BurgerService.java(All logic)Postman screenshots
Answer the question:
π§ Reflection Prompt
Ask each student:
βWhatβs one benefit of having a service layer you experienced personally while building this?β
π¦ Optional Extension (if time permits)
DrinkDrinkServiceBeta Was this translation helpful? Give feedback.
All reactions