Commit 49019ac4 authored by Alex Pinto's avatar Alex Pinto

WIP: trying to fix endpoints

parent 88155b03
......@@ -80,6 +80,11 @@
<artifactId>google-api-client</artifactId>
<version>1.31.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.validation.Valid;
@RestController
@RequestMapping(value = "/api")
public class WarehouseController {
......@@ -32,7 +34,7 @@ public class WarehouseController {
@CrossOrigin
@PostMapping(value = "/orders")
public Mono<WarehouseOrder> createOrder(@RequestBody WarehouseOrder order) {
public Mono<WarehouseOrder> createOrder(@Valid @RequestBody WarehouseOrder order) {
return orderService.createOrder(order);
}
......
package com.ascendfinalproject.warehouse.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {
public NotFoundException() {
super();
}
public NotFoundException(String message) {
super(message);
}
}
package com.ascendfinalproject.warehouse.repositories;
import com.ascendfinalproject.warehouse.models.Session;
import org.springframework.data.repository.CrudRepository;
public interface SessionRepository extends CrudRepository<Session, String> {
}
......@@ -30,7 +30,7 @@ public class SessionService {
}
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(null);
.body(session);
}
......
package com.ascendfinalproject.warehouse.services;
import com.ascendfinalproject.warehouse.exceptions.NotFoundException;
import com.ascendfinalproject.warehouse.models.Item;
import com.ascendfinalproject.warehouse.models.WarehouseOrder;
import com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -21,6 +24,7 @@ public class WarehouseOrderService {
public Mono<WarehouseOrder> findOrderById(String id) {
return orderRepository.findById(id);
// .switchIfEmpty(ServerResponse.notFound().build());
}
public Flux<WarehouseOrder> getOrders() {
......@@ -42,6 +46,9 @@ public class WarehouseOrderService {
public Mono<WarehouseOrder> updateOrder(WarehouseOrder order, String id) {
return orderRepository.findById(id)
.doOnError(error -> {
throw new NotFoundException("Warehouse order of ID: " + id + " not found");
})
.flatMap(existingOrder -> {
existingOrder.setStatus(order.getStatus());
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