File tree Expand file tree Collapse file tree 1 file changed +36
-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 +36
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .codedifferently .lesson26 .web ;
2+
3+ import java .io .IOException ;
4+ import java .util .List ;
5+ import java .util .Set ;
6+
7+ import org .springframework .http .ResponseEntity ;
8+ import org .springframework .web .bind .annotation .CrossOrigin ;
9+ import org .springframework .web .bind .annotation .GetMapping ;
10+ import org .springframework .web .bind .annotation .RestController ;
11+
12+ import com .codedifferently .lesson26 .library .Librarian ;
13+ import com .codedifferently .lesson26 .library .Library ;
14+ import com .codedifferently .lesson26 .library .MediaItem ;
15+ import com .codedifferently .lesson26 .library .search .SearchCriteria ;
16+
17+ @ RestController
18+ @ CrossOrigin
19+ public class MediaItemsController {
20+
21+ private final Library library ;
22+ private final Librarian librarian ;
23+
24+ public MediaItemsController (Library library ) throws IOException {
25+ this .library = library ;
26+ this .librarian = library .getLibrarians ().stream ().findFirst ().orElseThrow ();
27+ }
28+
29+ @ GetMapping ("/items" )
30+ public ResponseEntity <GetMediaItemsResponse > getItems () {
31+ Set <MediaItem > items = library .search (SearchCriteria .builder ().build ());
32+ List <MediaItemResponse > responseItems = items .stream ().map (MediaItemResponse ::from ).toList ();
33+ var response = GetMediaItemsResponse .builder ().items (responseItems ).build ();
34+ return ResponseEntity .ok (response );
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments