File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 66import com .codedifferently .lesson26 .library .search .SearchCriteria ;
77import java .io .IOException ;
88import java .util .List ;
9+ import java .util .Optional ;
910import java .util .Set ;
11+ import java .util .UUID ;
12+
1013import org .springframework .http .ResponseEntity ;
1114import org .springframework .web .bind .annotation .CrossOrigin ;
1215import org .springframework .web .bind .annotation .GetMapping ;
@@ -27,8 +30,20 @@ public MediaItemsController(Library library) throws IOException {
2730 @ GetMapping ("/items" )
2831 public ResponseEntity <GetMediaItemsResponse > getItems () {
2932 Set <MediaItem > items = library .search (SearchCriteria .builder ().build ());
33+ if (items .isEmpty ()) {
34+ ResponseEntity .noContent ();
35+ }
3036 List <MediaItemResponse > responseItems = items .stream ().map (MediaItemResponse ::from ).toList ();
3137 var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
3238 return ResponseEntity .ok (response );
3339 }
40+ @ GetMapping (value = "/{id}" )
41+ public ResponseEntity <MediaItemResponse > getItemById (@ PathVariable ("id" ) UUID id ) {
42+
43+ System .out .println (id .toString ());
44+
45+ Set <MediaItem > items = library .search (SearchCriteria .builder ().id (id .toString ()).build ());
46+ Optional <MediaItem > matchedItem =
47+ items .stream ().filter (item -> item .getId ().equals (id )).findFirst ();
48+ System .out .println ("items" );
3449}
You can’t perform that action at this time.
0 commit comments