File tree Expand file tree Collapse file tree 2 files changed +30
-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 +30
-0
lines changed Original file line number Diff line number Diff line change 8
8
import java .util .List ;
9
9
import java .util .Set ;
10
10
import org .springframework .web .bind .annotation .CrossOrigin ;
11
+ import org .springframework .web .bind .annotation .DeleteMapping ;
11
12
import org .springframework .web .bind .annotation .GetMapping ;
13
+ import org .springframework .web .bind .annotation .PathVariable ;
12
14
import org .springframework .web .bind .annotation .RestController ;
13
15
14
16
@ RestController
@@ -29,4 +31,26 @@ public GetMediaItemsResponse getItems() {
29
31
var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
30
32
return response ;
31
33
}
34
+
35
+ @ GetMapping ("/items" )
36
+ public GetMediaItemsResponse postItems () {
37
+ Set <MediaItem > items = library .search (SearchCriteria .builder ().build ());
38
+ List <MediaItemResponse > responseItems = items .stream ().map (MediaItemResponse ::from ).toList ();
39
+ return postItems ();
40
+ }
41
+
42
+ @ GetMapping ("/items/:id" )
43
+ public GetMediaItemsResponse getItemsId (@ PathVariable String id ) {
44
+ Set <MediaItem > items = library .search (SearchCriteria .builder ().id (id ).build ());
45
+ MediaItemResponse responseItem = items .stream ().map (MediaItemResponse ::from ).iterator ().next ();
46
+ return GetMediaItemsResponse .builder ().item (responseItem ).build ();
47
+ }
48
+
49
+ @ DeleteMapping (value = "{id}" )
50
+ public void deletebById (@ PathVariable String id ) {
51
+ Set <MediaItem > items = library .search (SearchCriteria .builder ().id (id ).build ());
52
+ MediaItem item = items .iterator ().next ();
53
+ library .removeMediaItem (item , librarian );
54
+ }
55
+
32
56
}
You can’t perform that action at this time.
0 commit comments