Commit f9d7b5e3 authored by Darrick Yong's avatar Darrick Yong

merge master

parents 746c5bd5 23cc8f3a
......@@ -33,4 +33,4 @@ build/
.vscode/
/frontend/node_modules/
/frontend/src/config/
\ No newline at end of file
/frontend/src/config/*
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
import React from 'react';
import { GoogleLogin } from "react-google-login";
import keys from '../../config/keys_dev'
import keys from "../../config/keys_dev"
const clientId = keys.clientId;
......
......@@ -29,6 +29,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
......
package com.ascendfinalproject.warehouse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import java.io.IOException;
@Service
public class Consumer {
private final Logger logger = LoggerFactory.getLogger(Consumer.class);
// this is placeholder
@KafkaListener(topics = "fulfilled", groupId = "WAREHOUSE_MANAGEMENT")
public void consume(String message) throws IOException {
logger.info(String.format("#### -> Consumed message -> %s", message));
}
}
package com.ascendfinalproject.warehouse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
@Service
public class Producer {
private static final Logger logger = LoggerFactory.getLogger(Producer.class);
private static final String FULFILLED = "fulfilled";
private static final String CANCELLED = "cancelled";
@Autowired
// publish messages to the topic
private KafkaTemplate<String, String> kafkaTemplate;
public void orderFulfilled(String message) {
logger.info(String.format("#### -> this order is fulfilled -> %s", message));
this.kafkaTemplate.send(FULFILLED, message);
}
public void orderCancelled(String message) {
logger.info(String.format("#### -> this order is cancelled -> %s", message));
this.kafkaTemplate.send(CANCELLED, message);
}
}
......@@ -11,3 +11,4 @@ public class WarehouseApplication {
}
}
package com.ascendfinalproject.warehouse.controllers;
import com.ascendfinalproject.warehouse.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/kafka")
public class KafkaController {
private final Producer producer;
@Autowired
KafkaController(Producer producer) {
this.producer = producer;
}
@PostMapping(value = "/fulfilled")
public void sendMessageToKafkaTopic(@RequestParam("message") String message) {
this.producer.orderFulfilled(message);
}
}
package com.ascendfinalproject.warehouse.controllers;
import com.ascendfinalproject.warehouse.models.OrderResponse;
import com.ascendfinalproject.warehouse.models.WarehouseOrder;
import com.ascendfinalproject.warehouse.services.WarehouseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -22,7 +24,7 @@ public class WarehouseController {
@CrossOrigin
@GetMapping("/orders/{id}")
public Mono<WarehouseOrder> findStudent(@PathVariable String id){
public Mono<WarehouseOrder> findOrder(@PathVariable String id){
return orderService.findOrderById(id);
}
......
package com.ascendfinalproject.warehouse.models;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
@Getter
@Setter
public class Item {
private String itemId;
private String itemName;
private int itemQuantity;
private int itemPrice;
private int itemSku;
public Item(String itemId, String itemName, int itemQuantity, int itemPrice, int itemSku) {
this.itemId = itemId;
this.itemName = itemName;
this.itemQuantity = itemQuantity;
this.itemPrice = itemPrice;
this.itemSku = itemSku;
}
}
......@@ -17,4 +17,11 @@ public class OrderResponse {
allIds.add(id);
}
@Override
public String toString() {
return "OrderResponse{" +
"allIds=" + allIds +
", byId=" + byId +
'}';
}
}
......@@ -4,6 +4,9 @@ import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import java.util.Date;
import java.util.List;
@Getter
@Setter
public class WarehouseOrder {
......@@ -11,6 +14,10 @@ public class WarehouseOrder {
private String id;
private String orderId;
private String status;
private Date createdAt;
private Date modifiedAt;
private List<Item> orderItems;
private String address;
public WarehouseOrder() {
}
......
package com.ascendfinalproject.warehouse.services;
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;
......@@ -7,6 +8,11 @@ import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
public class WarehouseOrderService {
......@@ -19,25 +25,26 @@ public class WarehouseOrderService {
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) {
order.setStatus("RECEIVED");
order.setCreatedAt(new Date(System.currentTimeMillis()));
order.setModifiedAt(new Date(System.currentTimeMillis()));
List<Item> itemList = Arrays.asList(
new Item("3", "Hamburger", 3, 3, 33),
new Item("4", "Sausage", 4, 5, 66),
new Item("5", "Fries", 3, 4, 33));
order.setOrderItems(itemList);
order.setAddress("123 apple st");
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());
existingOrder.setModifiedAt(new Date(System.currentTimeMillis()));
return orderRepository.save(existingOrder);
});
......
spring.data.mongodb.uri=mongodb+srv://warehouse1:ascendWarehouseProject@warehouse-cluster.xopll.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
spring.data.mongodb.database=test
server:
port: 9000
spring:
kafka:
consumer:
bootstrap-servers: localhost:9092
group-id: WAREHOUSE_MANAGEMENT
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
producer:
bootstrap-servers: localhost:9092
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
\ No newline at end of file
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