44import com .codedifferently .lesson26 .library .Library ;
55import com .codedifferently .lesson26 .library .MediaItem ;
66import com .codedifferently .lesson26 .library .search .SearchCriteria ;
7-
87import jakarta .validation .Valid ;
9-
10- import org .springframework .web .bind .annotation .RequestBody ;
11-
12-
138import java .io .IOException ;
149import java .util .List ;
1510import java .util .Set ;
1611import java .util .UUID ;
17-
1812import org .springframework .http .ResponseEntity ;
1913import org .springframework .web .bind .MethodArgumentNotValidException ;
2014import org .springframework .web .bind .annotation .CrossOrigin ;
2115import org .springframework .web .bind .annotation .DeleteMapping ;
2216import org .springframework .web .bind .annotation .GetMapping ;
2317import org .springframework .web .bind .annotation .PathVariable ;
2418import org .springframework .web .bind .annotation .PostMapping ;
19+ import org .springframework .web .bind .annotation .RequestBody ;
2520import org .springframework .web .bind .annotation .RestController ;
2621
2722@ RestController
@@ -51,7 +46,7 @@ public ResponseEntity<MediaItemResponse> getItemById(@PathVariable("id") UUID id
5146 Set <MediaItem > foundItems = library .search (searchCriteria );
5247
5348 if (foundItems .isEmpty ()) {
54- return ResponseEntity .notFound ().build ();
49+ return ResponseEntity .notFound ().build ();
5550 }
5651
5752 MediaItem item = foundItems .iterator ().next ();
@@ -61,35 +56,32 @@ public ResponseEntity<MediaItemResponse> getItemById(@PathVariable("id") UUID id
6156 }
6257
6358 @ PostMapping ("/items" )
64- public CreateMediaItemResponse createMediaItem (@ RequestBody @ Valid CreateMediaItemRequest request ) throws MethodArgumentNotValidException {
59+ public CreateMediaItemResponse createMediaItem (@ RequestBody @ Valid CreateMediaItemRequest request )
60+ throws MethodArgumentNotValidException {
6561
6662 MediaItemRequest itemRequest = request .getItem ();
6763
68-
6964 System .out .println (request );
7065
71-
7266 var item = MediaItemRequest .asMediaItem (itemRequest );
7367
7468 library .addMediaItem (item , librarian );
7569
76- var response = CreateMediaItemResponse .builder ().item (getItemById (item .getId ()).getBody ()).build ();
70+ var response =
71+ CreateMediaItemResponse .builder ().item (getItemById (item .getId ()).getBody ()).build ();
7772
7873 return response ;
7974 }
8075
8176 @ DeleteMapping ("/items/{id}" )
82- public ResponseEntity <Void > deleteItem (@ PathVariable ("id" ) UUID id ){
77+ public ResponseEntity <Void > deleteItem (@ PathVariable ("id" ) UUID id ) {
8378
84-
85- if (getItemById (id ).getBody () == null ) {
79+ if (getItemById (id ).getBody () == null ) {
8680 return ResponseEntity .notFound ().build ();
8781 }
8882
8983 library .removeMediaItem (id , librarian );
9084
91-
9285 return ResponseEntity .noContent ().build ();
93-
9486 }
9587}
0 commit comments