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 9
9
import java .util .Set ;
10
10
import org .springframework .http .ResponseEntity ;
11
11
import org .springframework .web .bind .annotation .CrossOrigin ;
12
+ import org .springframework .web .bind .annotation .DeleteMapping ;
12
13
import org .springframework .web .bind .annotation .GetMapping ;
14
+ import org .springframework .web .bind .annotation .PostMapping ;
13
15
import org .springframework .web .bind .annotation .RestController ;
14
16
15
17
@ RestController
@@ -31,4 +33,36 @@ public ResponseEntity<GetMediaItemsResponse> getItems() {
31
33
var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
32
34
return ResponseEntity .ok (response );
33
35
}
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
+
34
67
}
68
+
You can’t perform that action at this time.
0 commit comments