@@ -131,6 +131,7 @@ public ResponseEntity<VehicleInspection> getById(@PathVariable Long id) {
131131 .orElse (ResponseEntity .notFound ().build ());
132132 }
133133
134+
134135 /**
135136 * JPA Get By Example Query - Needs an Index to be efficient It still finds ALL the results each
136137 * time and returns a subset
@@ -141,15 +142,23 @@ public ResponseEntity<PageDto<VehicleInspection>> getInspectionsByModel(
141142 @ RequestParam (name = "page" , required = false , defaultValue = "0" ) int page ,
142143 @ RequestParam (name = "size" , required = false , defaultValue = "10" ) int size ) {
143144
144- // This is where we are hard coding a query for this endpoint.
145- // By creating an example of the class, clumsy but works.
146- VehicleInspection example = new VehicleInspection ();
147- Vehicle v = new Vehicle ();
148- v .setModel (model );
149- example .setVehicle (v );
150-
151145 // Use the line below for immutable model
152146 // VehicleInspection probe = VehicleInspection.builder().model(model).build();
147+ Slice <VehicleInspection > returnPage = queryService .getByVehicleModel (model , page , size );
148+ PageDto <VehicleInspection > entity = new PageDto <>(returnPage );
149+ return ResponseEntity .ok (entity );
150+ }
151+
152+ /**
153+ * JPA Get By Example Query , pass in some fields get matching in pages
154+ * Post as we are sending a body
155+ */
156+
157+ @ PostMapping ("/inspections/byExample" )
158+ public ResponseEntity <PageDto <VehicleInspection >> getInspectionByExample (
159+ @ RequestBody VehicleInspection example ,
160+ @ RequestParam (name = "page" , required = false , defaultValue = "0" ) int page ,
161+ @ RequestParam (name = "size" , required = false , defaultValue = "10" ) int size ) {
153162 Slice <VehicleInspection > returnPage = queryService .getByExample (example , page , size );
154163 PageDto <VehicleInspection > entity = new PageDto <>(returnPage );
155164 return ResponseEntity .ok (entity );
0 commit comments