Skip to content

Conversation

@txjackson252
Copy link
Contributor

This is my lesson_23 homework on Web APIs using REST.

Added the MediaItemsController to handle API requests for the library app.
Includes GET, POST, and DELETE routes for media items with validation and error handling.
All tests in MediaItemsControllerTest now pass successfully.

For this homework, it was interesting to see how the methods came out to cover the tests. I struggled a bit with the post method as there seemed to be many different ways to do it.

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: Trinitie Jackson
Date: 10/7/2025

Feedback

The submission demonstrates a good understanding of API development and HTTP protocol concepts. The student has implemented the required endpoints, including GET, POST, and DELETE operations, and has made appropriate use of the Spring framework annotations. However, there are some discrepancies compared to the sample solution. For instance, the getItemById method uses GetMediaItemsResponse instead of MediaItemResponse, which might not align with expected response structures. Additionally, the addNewItem method does not use the @Valid annotation for request validation, which could lead to issues if the request object is malformed. The use of Map for error responses is a good approach, but it deviates from the sample solution's use of specific response classes, which might affect consistency and clarity. The code is generally well-formatted, but there are some unnecessary imports and reordering of imports that could be cleaned up. Overall, the code is functional and technically sound, but there are areas for improvement in aligning with the sample solution and ensuring consistency in response handling.


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

@anthonydmays anthonydmays reopened this Oct 8, 2025
@txjackson252
Copy link
Contributor Author

I have just made the adjustments with the feedback given.

@PostMapping("/items")
public ResponseEntity<?> addNewItem(
@Valid @RequestBody(required = false) CreateMediaItemRequest request) {
if (request == null || request.getItem() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't need this.

MediaItem item = MediaItemRequest.asMediaItem(request.getItem());
library.addMediaItem(item, librarian);
return ResponseEntity.ok(Map.of("item", MediaItemResponse.from(item)));
} catch (IllegalArgumentException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this either if you just use the @Valid annotation (which you did).

}

@DeleteMapping("/items/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable String id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Better to take a UUID.

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.

2 participants