44import dev .ancaghenade .shipmentlistdemo .entity .Shipment ;
55import dev .ancaghenade .shipmentlistdemo .service .ShipmentService ;
66import java .util .List ;
7+ import org .springframework .beans .factory .annotation .Autowired ;
78import org .springframework .http .MediaType ;
89import org .springframework .web .bind .annotation .CrossOrigin ;
910import org .springframework .web .bind .annotation .DeleteMapping ;
1011import org .springframework .web .bind .annotation .GetMapping ;
1112import org .springframework .web .bind .annotation .PathVariable ;
1213import org .springframework .web .bind .annotation .PostMapping ;
14+ import org .springframework .web .bind .annotation .RequestBody ;
1315import org .springframework .web .bind .annotation .RequestMapping ;
1416import org .springframework .web .bind .annotation .RequestParam ;
1517import org .springframework .web .bind .annotation .RestController ;
@@ -22,6 +24,7 @@ public class ShipmentController {
2224
2325 private final ShipmentService shipmentService ;
2426
27+ @ Autowired
2528 public ShipmentController (ShipmentService shipmentService ) {
2629 this .shipmentService = shipmentService ;
2730 }
@@ -31,6 +34,12 @@ public List<Shipment> getAllShipments() {
3134 return shipmentService .getAllShipments ();
3235 }
3336
37+ @ GetMapping (
38+ path = "{shipmentId}/image/download" , produces = MediaType .IMAGE_JPEG_VALUE )
39+ public byte [] downloadShipmentImage (@ PathVariable ("shipmentId" ) String shipmentId ) {
40+ return shipmentService .downloadShipmentImage (shipmentId );
41+ }
42+
3443 @ DeleteMapping ("/{shipmentId}" )
3544 public String deleteShipment (@ PathVariable ("shipmentId" ) String shipmentId ) {
3645 return shipmentService .deleteShipment (shipmentId );
@@ -45,10 +54,11 @@ public void uploadShipmentImage(@PathVariable("shipmentId") String shipmentId,
4554 shipmentService .uploadShipmentImage (shipmentId , file );
4655 }
4756
48-
49- @ GetMapping (
50- path = "{shipmentId}/image/download" , produces = MediaType .IMAGE_JPEG_VALUE )
51- public byte [] downloadShipmentImage ( @ PathVariable ( "shipmentId" ) String shipmentId ) {
52- return shipmentService .downloadShipmentImage ( shipmentId );
57+ @ PostMapping (
58+ consumes = MediaType . APPLICATION_JSON_VALUE ,
59+ produces = MediaType .APPLICATION_JSON_VALUE )
60+ public void saveUpdateShipment ( @ RequestBody Shipment shipment ) {
61+ shipmentService .saveShipment ( shipment );
5362 }
63+
5464}
0 commit comments