File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 99import java .util .Set ;
1010import org .springframework .http .ResponseEntity ;
1111import org .springframework .web .bind .annotation .CrossOrigin ;
12+ import org .springframework .web .bind .annotation .DeleteMapping ;
1213import org .springframework .web .bind .annotation .GetMapping ;
14+ import org .springframework .web .bind .annotation .PostMapping ;
1315import org .springframework .web .bind .annotation .RestController ;
1416
1517@ RestController
@@ -31,4 +33,36 @@ public ResponseEntity<GetMediaItemsResponse> getItems() {
3133 var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
3234 return ResponseEntity .ok (response );
3335 }
36+
37+ /**
38+ * @param id
39+ * @return
40+ */
41+ @ PostMapping ("/items/{id}" )
42+ public ResponseEntity <MediaItemResponse > getItemById (String id ) {
43+ MediaItem item = librarian .getItemById (id );
44+ MediaItemResponse response = MediaItemResponse .from (item );
45+ return ResponseEntity .ok (response );
46+ }
47+
48+ /**
49+ * @param id
50+ * @return
51+ */
52+ @ DeleteMapping ("/items/{id}" )
53+ public ResponseEntity <Void > deleteItemById (String id ) {
54+ SearchCriteria criteria = SearchCriteria .builder ().id (id ).build ();
55+ Set <MediaItem > items = library .search (criteria );
56+ if (items .isEmpty ()) {
57+ return ResponseEntity .notFound ().build ();
58+ }
59+ MediaItem item = items .iterator ().next ();
60+
61+ librarian .deleteItemById (id );
62+ return ResponseEntity .noContent ().build ();
63+
64+
65+ }
66+
3467}
68+
You can’t perform that action at this time.
0 commit comments