Skip to content

Commit 570f432

Browse files
fix: changed the id type in deleteItem method
1 parent c702f35 commit 570f432

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web/MediaItemsController.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,18 @@ public ResponseEntity<MediaItemResponse> getItemById(@PathVariable UUID id) {
6565
}
6666

6767
@DeleteMapping("/items/{id}")
68-
public ResponseEntity<Void> deleteItem(@PathVariable String id) { // Takes String id
69-
UUID itemUuid;
70-
71-
try {
72-
itemUuid = UUID.fromString(id);
73-
} catch (IllegalArgumentException e) {
74-
return ResponseEntity.badRequest().build();
75-
}
68+
public ResponseEntity<Void> deleteItem(@PathVariable UUID id) {
7669

7770
Set<MediaItem> items = library.search(SearchCriteria.builder().build());
7871
MediaItem foundItem =
79-
items.stream().filter(item -> item.getId().equals(itemUuid)).findFirst().orElse(null);
72+
items.stream().filter(item -> item.getId().equals(id)).findFirst().orElse(null);
8073

8174
if (foundItem == null) {
8275
return ResponseEntity.notFound().build();
8376
}
8477

8578
try {
86-
library.removeMediaItem(itemUuid, this.librarian);
79+
library.removeMediaItem(id, this.librarian);
8780
return ResponseEntity.noContent().build();
8881
} catch (MediaItemCheckedOutException ex) {
8982
return ResponseEntity.status(HttpStatus.CONFLICT).build();

0 commit comments

Comments
 (0)