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
+ import jakarta .validation .Valid ;
3
8
import java .io .IOException ;
4
9
import java .util .List ;
5
10
import java .util .Set ;
6
-
7
11
import org .springframework .http .ResponseEntity ;
8
12
import org .springframework .web .bind .annotation .CrossOrigin ;
9
13
import org .springframework .web .bind .annotation .DeleteMapping ;
13
17
import org .springframework .web .bind .annotation .RequestBody ;
14
18
import org .springframework .web .bind .annotation .RestController ;
15
19
16
- import com .codedifferently .lesson26 .library .Librarian ;
17
- import com .codedifferently .lesson26 .library .Library ;
18
- import com .codedifferently .lesson26 .library .MediaItem ;
19
- import com .codedifferently .lesson26 .library .search .SearchCriteria ;
20
-
21
- import jakarta .validation .Valid ;
22
-
23
20
@ RestController
24
21
@ CrossOrigin
25
22
public class MediaItemsController {
@@ -44,15 +41,16 @@ public ResponseEntity<GetMediaItemsResponse> getItems() {
44
41
45
42
//
46
43
47
- @ DeleteMapping ("/items/{id}" )
44
+ @ DeleteMapping ("/items/{id}" )
48
45
public ResponseEntity <Void > deleteItem (@ PathVariable String id ) {
49
46
Set <MediaItem > items = library .search (SearchCriteria .builder ().id (id ).build ());
50
47
if (items .isEmpty ()) {
51
- return ResponseEntity .notFound ().build (); // Return 404 if item is not found
48
+ return ResponseEntity .notFound ().build (); // Return 404 if item is not found
52
49
}
53
50
MediaItem itemToDelete = items .iterator ().next ();
54
- library .removeMediaItem (itemToDelete , librarian ); // Assuming there's a method to remove items in the library
55
- return ResponseEntity .noContent ().build (); // Return 204 No Content if deletion is successful
51
+ library .removeMediaItem (
52
+ itemToDelete , librarian ); // Assuming there's a method to remove items in the library
53
+ return ResponseEntity .noContent ().build (); // Return 204 No Content if deletion is successful
56
54
}
57
55
58
56
//
@@ -61,7 +59,7 @@ public ResponseEntity<Void> deleteItem(@PathVariable String id) {
61
59
public ResponseEntity <MediaItemResponse > getItem (@ PathVariable String id ) {
62
60
Set <MediaItem > items = library .search (SearchCriteria .builder ().id (id ).build ());
63
61
if (items .isEmpty ()) {
64
- return ResponseEntity .notFound ().build (); // Return 404 if item is not found
62
+ return ResponseEntity .notFound ().build (); // Return 404 if item is not found
65
63
}
66
64
MediaItem item = items .iterator ().next ();
67
65
MediaItemResponse response = MediaItemResponse .from (item );
0 commit comments