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