4
4
import com .codedifferently .lesson26 .library .Library ;
5
5
import com .codedifferently .lesson26 .library .MediaItem ;
6
6
import com .codedifferently .lesson26 .library .search .SearchCriteria ;
7
-
8
7
import jakarta .validation .Valid ;
9
-
10
- import org .springframework .web .bind .annotation .RequestBody ;
11
-
12
-
13
8
import java .io .IOException ;
14
9
import java .util .List ;
15
10
import java .util .Set ;
16
11
import java .util .UUID ;
17
-
18
12
import org .springframework .http .ResponseEntity ;
19
13
import org .springframework .web .bind .MethodArgumentNotValidException ;
20
14
import org .springframework .web .bind .annotation .CrossOrigin ;
21
15
import org .springframework .web .bind .annotation .DeleteMapping ;
22
16
import org .springframework .web .bind .annotation .GetMapping ;
23
17
import org .springframework .web .bind .annotation .PathVariable ;
24
18
import org .springframework .web .bind .annotation .PostMapping ;
19
+ import org .springframework .web .bind .annotation .RequestBody ;
25
20
import org .springframework .web .bind .annotation .RestController ;
26
21
27
22
@ RestController
@@ -51,7 +46,7 @@ public ResponseEntity<MediaItemResponse> getItemById(@PathVariable("id") UUID id
51
46
Set <MediaItem > foundItems = library .search (searchCriteria );
52
47
53
48
if (foundItems .isEmpty ()) {
54
- return ResponseEntity .notFound ().build ();
49
+ return ResponseEntity .notFound ().build ();
55
50
}
56
51
57
52
MediaItem item = foundItems .iterator ().next ();
@@ -61,35 +56,32 @@ public ResponseEntity<MediaItemResponse> getItemById(@PathVariable("id") UUID id
61
56
}
62
57
63
58
@ PostMapping ("/items" )
64
- public CreateMediaItemResponse createMediaItem (@ RequestBody @ Valid CreateMediaItemRequest request ) throws MethodArgumentNotValidException {
59
+ public CreateMediaItemResponse createMediaItem (@ RequestBody @ Valid CreateMediaItemRequest request )
60
+ throws MethodArgumentNotValidException {
65
61
66
62
MediaItemRequest itemRequest = request .getItem ();
67
63
68
-
69
64
System .out .println (request );
70
65
71
-
72
66
var item = MediaItemRequest .asMediaItem (itemRequest );
73
67
74
68
library .addMediaItem (item , librarian );
75
69
76
- var response = CreateMediaItemResponse .builder ().item (getItemById (item .getId ()).getBody ()).build ();
70
+ var response =
71
+ CreateMediaItemResponse .builder ().item (getItemById (item .getId ()).getBody ()).build ();
77
72
78
73
return response ;
79
74
}
80
75
81
76
@ DeleteMapping ("/items/{id}" )
82
- public ResponseEntity <Void > deleteItem (@ PathVariable ("id" ) UUID id ){
77
+ public ResponseEntity <Void > deleteItem (@ PathVariable ("id" ) UUID id ) {
83
78
84
-
85
- if (getItemById (id ).getBody () == null ) {
79
+ if (getItemById (id ).getBody () == null ) {
86
80
return ResponseEntity .notFound ().build ();
87
81
}
88
82
89
83
library .removeMediaItem (id , librarian );
90
84
91
-
92
85
return ResponseEntity .noContent ().build ();
93
-
94
86
}
95
87
}
0 commit comments