Commit 7514afb5 authored by Darrick Yong's avatar Darrick Yong

Merge branch 'master' into feat/oauth

parents 512ba9cb 18141a34
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -59,7 +59,17 @@
<scope>test</scope>
</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>
<build>
......
......@@ -14,14 +14,28 @@ public class WarehouseController {
@Autowired
WarehouseOrderService orderService;
@CrossOrigin
@GetMapping(value = "/orders")
public Flux<WarehouseOrder> getOrders() {
return orderService.getOrders();
}
@CrossOrigin
@GetMapping("/orders/{id}")
public Mono<WarehouseOrder> findStudent(@PathVariable String id){
return orderService.findOrderById(id);
}
@CrossOrigin
@PostMapping(value = "/orders")
public Mono<WarehouseOrder> createOrder(@RequestBody WarehouseOrder 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;
import com.ascendfinalproject.warehouse.models.WarehouseOrder;
import com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -14,12 +13,34 @@ public class WarehouseOrderService {
@Autowired
WarehouseOrderRepository orderRepository;
public Mono<WarehouseOrder> findOrderById(String id) {
return orderRepository.findById(id);
}
public Flux<WarehouseOrder> getOrders() {
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) {
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