Skip to content

Conversation

@dev-benson-03
Copy link
Contributor

@dev-benson-03 dev-benson-03 commented Oct 6, 2025

PR: Implement Missing Media Item Endpoints (GET by ID, POST, DELETE) – Lesson 23 Java API

Summary

Implemented full REST support in MediaItemsController:

  • GET /items
  • GET /items/{id}
  • POST /items
  • DELETE /items/{id}

Includes validation handling, error shaping, consistent response models, and item lookup helper.

Endpoints

Method Path Success Response Error Responses
GET /items 200 { "items": [ ... ] }
GET /items/{id} 200 { ...item } 404 Not Found
POST /items 200 { "item": { ... } } 400 { "errors": [ ... ] }
DELETE /items/{id} 204 No Content 404 Not Found

POST /items (valid)

Request:

json
{
  "item": {
    "id": "e27a4e0d-9664-420d-955e-c0e295d0ce02",
    "type": "BOOK",
    "title": "Becoming",
    "isbn": "9781524763138",
    "authors": ["Michelle Obama"],
    "pages": 448
  }
}

Response 200:

{
  "item": {
    "id": "e27a4e0d-9664-420d-955e-c0e295d0ce02",
    "type": "BOOK",
    "title": "Becoming",
    "isbn": "9781524763138",
    "authors": ["Michelle Obama"],
    "pages": 448
  }
}

POST /items (valid):

{ "errors": ["item is required"] }

Pseudocode Used Initially

if POST body.item missing -> 400 {errors:["item is required"]}
else map -> domain item, add, return 200 {item:...}

GET /items/{id} -> search; 404 if none else 200
DELETE /items/{id} -> search; 404 if none; remove; 204

Implementation Notes

  • Helper findItemById(String id) wraps library.search(...)
  • MediaItemRequest.asMediaItem performs polymorphic construction
  • Validation via @Valid + BindingResult; tailored single error for {} body
  • Inner ErrorResponse DTO for consistency
  • Delete converts path id to UUID and delegates to library.removeMediaItem

Struggles & Learning

Screenshot 2025-10-06 at 3 28 29 PM

Copy link
Contributor

@anthonydmays anthonydmays left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎓 Automated Grading Report

Student: Devyn Benson
Date: 10/7/2025

Feedback

The submission meets all functional requirements as outlined in the grading criteria. The student has successfully implemented the necessary API endpoints in the MediaItemsController.java file, including GET, POST, and DELETE operations. The code handles validation errors effectively in the POST request, providing meaningful error messages when input validation fails. The use of helper methods like findItemById improves code readability and reusability. All unit tests and GitHub checks pass, indicating the code is functionally correct and integrates well with the existing system.

From a technical perspective, the code is syntactically correct and well-formatted. The use of Java annotations and Spring's ResponseEntity is appropriate and follows best practices for RESTful API development. The inclusion of error handling and custom error responses enhances the robustness of the application. The code is organized, with clear separation of concerns, making it easy to maintain and extend. Overall, the implementation demonstrates a strong understanding of Java development, APIs, and HTTP protocols.


This is an automated preliminary review. Please review and adjust before finalizing.

@anthonydmays anthonydmays reopened this Oct 8, 2025
}

@PostMapping("/items")
public ResponseEntity<?> createItem(@Valid @RequestBody CreateMediaItemRequest request, BindingResult bindingResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ResponseEntity<CreateMediaItemResponse>.

.build();

return ResponseEntity.ok(response);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants