Fix/lesson 23 controller toby evans #812
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I made changes to my Lesson 23 homework by aligning MediaItems Controller with the sample solution. I restored use of a single, consistent Librarian (provided as a Spring @bean), changed GET /items/{id} to return MediaItemResponse, and updated POST /items to use CreateMediaItemRequest →→ CreateMediaItemResponse with a 201 Created response. I also removed ad-hoc new Librarian(...) calls and applied Spotless formatting. All changes were staged, committed, pushed (branch: fix/lesson-23-controller-toby-evans), and are ready for review.
Problem area (s):
• Creating a new Librarian per request instead of using a single injected instance
• Returning a Map instead of the provided response DTOs, causing response shape mismatches
• Test failures due to missing Spring bean for Librarian (unsatisfied dependency)
• Running Gradle tasks from the wrong directory/module at first
Lessons learned:
• Prefer dependency injection-provide shared collaborators (like Librarian) as Spring beans
• Follow the sample solution's request/response DTOs to keep APIs consistent and tests passing
• Run ./gradlew :api_app:spotlessApply and :api_app:check to catch formatting and compile issues early
• Use the module's Gradle wrapper and targeted tasks (e.g., lesson_23/api/java ./gradlew :api_app:check)