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;
import com.ascendfinalproject.warehouse.services.WarehouseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -27,8 +29,11 @@ public class WarehouseController {
@CrossOrigin
@GetMapping("/orders/{id}")
public Mono<WarehouseOrder> findOrder(@PathVariable String id){
return orderService.findOrderById(id);
public Mono<ResponseEntity> getById(@PathVariable String 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
......
......@@ -21,7 +21,7 @@ public class WarehouseOrderService {
@Autowired
WarehouseOrderRepository orderRepository;
public Mono<WarehouseOrder> findOrderById(String id) {
public Mono<WarehouseOrder> getById(String 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