Skip to content

Commit 136f967

Browse files
committed
feat:Adds Dasia's implement the MediaItemsController to enable the API to lesson_26
1 parent 141d135 commit 136f967

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lesson_26/api/java/api_app/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lesson_26/api/java/api_app/src/main/java/com/codedifferently/lesson26/web/MediaItemsController.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.util.List;
99
import java.util.Set;
1010
import org.springframework.web.bind.annotation.CrossOrigin;
11+
import org.springframework.web.bind.annotation.DeleteMapping;
1112
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.PathVariable;
1214
import org.springframework.web.bind.annotation.RestController;
1315

1416
@RestController
@@ -29,4 +31,26 @@ public GetMediaItemsResponse getItems() {
2931
var response = GetMediaItemsResponse.builder().items(responseItems).build();
3032
return response;
3133
}
34+
35+
@GetMapping("/items")
36+
public GetMediaItemsResponse postItems() {
37+
Set<MediaItem> items = library.search(SearchCriteria.builder().build());
38+
List<MediaItemResponse> responseItems = items.stream().map(MediaItemResponse::from).toList();
39+
return postItems();
40+
}
41+
42+
@GetMapping("/items/:id")
43+
public GetMediaItemsResponse getItemsId(@PathVariable String id) {
44+
Set<MediaItem> items = library.search(SearchCriteria.builder().id(id).build());
45+
MediaItemResponse responseItem = items.stream().map(MediaItemResponse::from).iterator().next();
46+
return GetMediaItemsResponse.builder().item(responseItem).build();
47+
}
48+
49+
@DeleteMapping(value = "{id}")
50+
public void deletebById(@PathVariable String id) {
51+
Set<MediaItem> items = library.search(SearchCriteria.builder().id(id).build());
52+
MediaItem item = items.iterator().next();
53+
library.removeMediaItem(item, librarian);
54+
}
55+
3256
}

0 commit comments

Comments
 (0)