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