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 6
6
import com .codedifferently .lesson26 .library .search .SearchCriteria ;
7
7
import java .io .IOException ;
8
8
import java .util .List ;
9
+ import java .util .Optional ;
9
10
import java .util .Set ;
11
+ import java .util .UUID ;
12
+
10
13
import org .springframework .http .ResponseEntity ;
11
14
import org .springframework .web .bind .annotation .CrossOrigin ;
12
15
import org .springframework .web .bind .annotation .GetMapping ;
@@ -27,8 +30,20 @@ public MediaItemsController(Library library) throws IOException {
27
30
@ GetMapping ("/items" )
28
31
public ResponseEntity <GetMediaItemsResponse > getItems () {
29
32
Set <MediaItem > items = library .search (SearchCriteria .builder ().build ());
33
+ if (items .isEmpty ()) {
34
+ ResponseEntity .noContent ();
35
+ }
30
36
List <MediaItemResponse > responseItems = items .stream ().map (MediaItemResponse ::from ).toList ();
31
37
var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
32
38
return ResponseEntity .ok (response );
33
39
}
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" );
34
49
}
You can’t perform that action at this time.
0 commit comments