Commit e2ed61e6 authored by Alex Pinto's avatar Alex Pinto

Merge branch 'feat/fix-getById' into 'master'

add error handling for getById

See merge request !13
parents ae3c1e20 8800fe97
...@@ -7,7 +7,9 @@ import com.ascendfinalproject.warehouse.services.SessionService; ...@@ -7,7 +7,9 @@ import com.ascendfinalproject.warehouse.services.SessionService;
import com.ascendfinalproject.warehouse.services.WarehouseOrderService; import com.ascendfinalproject.warehouse.services.WarehouseOrderService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -27,8 +29,11 @@ public class WarehouseController { ...@@ -27,8 +29,11 @@ public class WarehouseController {
@CrossOrigin @CrossOrigin
@GetMapping("/orders/{id}") @GetMapping("/orders/{id}")
public Mono<WarehouseOrder> findOrder(@PathVariable String id){ public Mono<ResponseEntity> getById(@PathVariable String id) {
return orderService.findOrderById(id); return orderService.getById(id)
.map(order -> (ResponseEntity.status(HttpStatus.OK).body(order)))
.cast(ResponseEntity.class)
.defaultIfEmpty(ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
} }
@CrossOrigin @CrossOrigin
......
...@@ -21,7 +21,7 @@ public class WarehouseOrderService { ...@@ -21,7 +21,7 @@ public class WarehouseOrderService {
@Autowired @Autowired
WarehouseOrderRepository orderRepository; WarehouseOrderRepository orderRepository;
public Mono<WarehouseOrder> findOrderById(String id) { public Mono<WarehouseOrder> getById(String id) {
return orderRepository.findById(id); return orderRepository.findById(id);
} }
......
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