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 88import java .util .List ;
99import java .util .Set ;
1010import org .springframework .web .bind .annotation .CrossOrigin ;
11+ import org .springframework .web .bind .annotation .DeleteMapping ;
1112import org .springframework .web .bind .annotation .GetMapping ;
13+ import org .springframework .web .bind .annotation .PathVariable ;
1214import org .springframework .web .bind .annotation .RestController ;
1315
1416@ RestController
@@ -29,4 +31,26 @@ public GetMediaItemsResponse getItems() {
2931 var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
3032 return response ;
3133 }
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+
3256}
You can’t perform that action at this time.
0 commit comments