Skip to main content

Three-Layer Mini-Stack

Challenge on lesson: Checkpoint: Architecture

CHALLENGE
Difficulty: intermediate+25 XP

Assemble the full stack in Solution: - record Task(String id, String title, boolean done) (domain) - interface TaskRepository { void save(Task t); Optional<Task> find(String id); List<Task> all(); } - static class InMemoryTaskRepository implements TaskRepository - static class TaskService with constructor (TaskRepository r): - Task create(String id, String title) โ€” blank title throws IllegalArgumentException; saves and returns - Task complete(String id) โ€” missing id throws NoSuchElementException; marks done and saves - List<Task> pending() โ€” all not-done tasks (insertion order) - record TaskView(String id, String title) (DTO) - static List<TaskView> pendingViews(TaskService s) โ€” the controller function mapping pending() to views. Then the test drives the whole graph: repo โ†’ service โ†’ views.

Back to lesson: Checkpoint: Architecture