Commit 8f6b9676 authored by Alex Pinto's avatar Alex Pinto

fixing up bug in update endpoint

parent e726d4e3
...@@ -42,8 +42,11 @@ public class WarehouseController { ...@@ -42,8 +42,11 @@ public class WarehouseController {
@CrossOrigin @CrossOrigin
@PutMapping(value = "/orders/{id}") @PutMapping(value = "/orders/{id}")
public Mono<WarehouseOrderResponse> updateOrder(@RequestBody WarehouseOrderResponse order, @PathVariable(value = "id") String id) { public Mono<ResponseEntity> updateOrder(@RequestBody WarehouseOrderResponse order, @PathVariable(value = "id") String id) {
return orderService.updateOrder(order, id); return orderService.updateOrder(order, id)
.map(updatedOrder -> (ResponseEntity.status(HttpStatus.OK).body(order)))
.cast(ResponseEntity.class)
.defaultIfEmpty(ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
} }
@CrossOrigin @CrossOrigin
......
...@@ -45,9 +45,6 @@ public class WarehouseOrderService { ...@@ -45,9 +45,6 @@ public class WarehouseOrderService {
public Mono<WarehouseOrderResponse> updateOrder(WarehouseOrderResponse order, String id) { public Mono<WarehouseOrderResponse> updateOrder(WarehouseOrderResponse order, String id) {
return orderRepository.findById(id) return orderRepository.findById(id)
.doOnError(error -> {
throw new NotFoundException("Warehouse order of ID: " + id + " not found");
})
.flatMap(existingOrder -> { .flatMap(existingOrder -> {
existingOrder.setStatus(order.getStatus()); existingOrder.setStatus(order.getStatus());
existingOrder.setModifiedAt(new Date(System.currentTimeMillis())); existingOrder.setModifiedAt(new Date(System.currentTimeMillis()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment