Commit 18141a34 authored by Philippe Fonzin's avatar Philippe Fonzin

Merge branch 'backend' into 'master'

finished inital routes and fixed cors error

See merge request !2
parents 28f95b55 d9cdaecc
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -59,7 +59,17 @@ ...@@ -59,7 +59,17 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-sync</artifactId> <version>4.0.5</version> </dependency> <dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -14,14 +14,28 @@ public class WarehouseController { ...@@ -14,14 +14,28 @@ public class WarehouseController {
@Autowired @Autowired
WarehouseOrderService orderService; WarehouseOrderService orderService;
@CrossOrigin
@GetMapping(value = "/orders") @GetMapping(value = "/orders")
public Flux<WarehouseOrder> getOrders() { public Flux<WarehouseOrder> getOrders() {
return orderService.getOrders(); return orderService.getOrders();
} }
@CrossOrigin
@GetMapping("/orders/{id}")
public Mono<WarehouseOrder> findStudent(@PathVariable String id){
return orderService.findOrderById(id);
}
@CrossOrigin
@PostMapping(value = "/orders") @PostMapping(value = "/orders")
public Mono<WarehouseOrder> createOrder(@RequestBody WarehouseOrder order) { public Mono<WarehouseOrder> createOrder(@RequestBody WarehouseOrder order) {
return orderService.createOrder(order); return orderService.createOrder(order);
} }
@CrossOrigin
@PutMapping(value = "/orders/{id}")
public Mono<WarehouseOrder> updateOrder(@RequestBody WarehouseOrder order, @PathVariable(value = "id") String id) {
return orderService.updateOrder(order, id);
}
} }
package com.ascendfinalproject.warehouse.models;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.List;
@Getter
@Setter
public class OrderResponse {
private List<String> allIds;
private HashMap<String, WarehouseOrder> byId;
public void appendId(String id) {
allIds.add(id);
}
}
...@@ -3,7 +3,6 @@ package com.ascendfinalproject.warehouse.services; ...@@ -3,7 +3,6 @@ package com.ascendfinalproject.warehouse.services;
import com.ascendfinalproject.warehouse.models.WarehouseOrder; import com.ascendfinalproject.warehouse.models.WarehouseOrder;
import com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository; import com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -14,12 +13,34 @@ public class WarehouseOrderService { ...@@ -14,12 +13,34 @@ public class WarehouseOrderService {
@Autowired @Autowired
WarehouseOrderRepository orderRepository; WarehouseOrderRepository orderRepository;
public Mono<WarehouseOrder> findOrderById(String id) {
return orderRepository.findById(id);
}
public Flux<WarehouseOrder> getOrders() { public Flux<WarehouseOrder> getOrders() {
return orderRepository.findAll(); return orderRepository.findAll();
// OrderResponse response = new OrderResponse();
// orderRepository.findAll()
// .flatMap(order -> {
// response.appendId(order.getId());
// response.getById().put(order.getId(), order);
// });
//
// return response;
} }
public Mono<WarehouseOrder> createOrder(WarehouseOrder order) { public Mono<WarehouseOrder> createOrder(WarehouseOrder order) {
return orderRepository.save(order); return orderRepository.save(order);
} }
public Mono<WarehouseOrder> updateOrder(WarehouseOrder order, String id) {
return orderRepository.findById(id)
.flatMap(existingOrder -> {
existingOrder.setOrderId(order.getOrderId());
existingOrder.setStatus(order.getStatus());
return orderRepository.save(existingOrder);
});
}
} }
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