From 1338a75915e03d2b417a51ee5187d106f698f004 Mon Sep 17 00:00:00 2001 From: ganny26 Date: Wed, 9 Mar 2022 16:57:37 +0530 Subject: [PATCH] Added UI for demo --- .../controller/OrderController.java | 1 + .../orderservice/entity/Order.java | 2 +- .../orderservice/entity/User.java | 2 +- .../controller/PaymentController.java | 2 + ui/index.html | 23 ++++ ui/src/main.js | 130 ++++++++++++++++++ .../controller/UserController.java | 1 + .../com/signoz/userservice/entity/Users.java | 2 +- 8 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 ui/index.html create mode 100644 ui/src/main.js diff --git a/order-service/src/main/java/com/signoz/orderservice/orderservice/controller/OrderController.java b/order-service/src/main/java/com/signoz/orderservice/orderservice/controller/OrderController.java index 890a33f..4f01f30 100644 --- a/order-service/src/main/java/com/signoz/orderservice/orderservice/controller/OrderController.java +++ b/order-service/src/main/java/com/signoz/orderservice/orderservice/controller/OrderController.java @@ -11,6 +11,7 @@ @RestController @RequestMapping("/orders") +@CrossOrigin(origins = "*") public class OrderController { @Autowired diff --git a/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/Order.java b/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/Order.java index 57f6bf6..172790e 100644 --- a/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/Order.java +++ b/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/Order.java @@ -15,7 +15,7 @@ @AllArgsConstructor @NoArgsConstructor @Entity -@Table(name = "orders") +@Table(name = "orders_tbl") @EntityListeners(AuditingEntityListener.class) public class Order { diff --git a/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/User.java b/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/User.java index a42b6b8..e46fd7b 100644 --- a/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/User.java +++ b/order-service/src/main/java/com/signoz/orderservice/orderservice/entity/User.java @@ -15,7 +15,7 @@ @AllArgsConstructor @NoArgsConstructor @Entity -@Table(name = "users") +@Table(name = "users_tbl") @EntityListeners(AuditingEntityListener.class) public class User { diff --git a/payment-service/src/main/java/com/signoz/paymentservice/controller/PaymentController.java b/payment-service/src/main/java/com/signoz/paymentservice/controller/PaymentController.java index f9110af..c436b91 100644 --- a/payment-service/src/main/java/com/signoz/paymentservice/controller/PaymentController.java +++ b/payment-service/src/main/java/com/signoz/paymentservice/controller/PaymentController.java @@ -21,9 +21,11 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/payment") +@CrossOrigin(origins = "*") public class PaymentController { private final Logger LOGGER = LoggerFactory.getLogger(PaymentController.class); private static final Tracer tracer = diff --git a/ui/index.html b/ui/index.html new file mode 100644 index 0000000..f88792a --- /dev/null +++ b/ui/index.html @@ -0,0 +1,23 @@ + + + + + + + OTEL Demo + + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/ui/src/main.js b/ui/src/main.js new file mode 100644 index 0000000..9df595b --- /dev/null +++ b/ui/src/main.js @@ -0,0 +1,130 @@ +// Application urls +const DEFAULT_SIGNOZ_URL = 'http://localhost:3301/application' +const USER_SERVICE_URL = 'http://localhost:8081/users' +const PAYMENT_SERVICE_URL = 'http://localhost:8082/payment' +const ORDER_SERVICE_URL = 'http://localhost:8083/orders' +// Components +const Title = (props) =>

{props.label}

+const Response = (props) =>
{JSON.stringify(props.result, null, 4)}
+const ProductDD = (props) => { + return ( + + ) +} +const App = () => { + let [user, setUser] = React.useState() + let [payment, setPayment] = React.useState() + let [order, setOrder] = React.useState() + let [product, setProduct] = React.useState() + let [signozUrl, setSignozUrl] = React.useState(DEFAULT_SIGNOZ_URL) + let createUser = async () => { + try { + const requestOptions = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + userName: 'Rahul', + account: 'BCED1233F', + }), + } + let response = await fetch(`${USER_SERVICE_URL}/create`, requestOptions) + let result = await response.json() + setUser(result) + console.log(result) + } catch (error) { + setUser(error.message) + console.log('err', error.message) + } + } + + let handleProduct = (e) => { + let { options, value } = e.target + setProduct({ + PRODUCT_NAME: options[options.selectedIndex].text, + PRICE: String(value), + }) + } + let transferFund = async () => { + console.log('transferFund', user) + const requestOptions = { + method: 'GET', + } + let response = await fetch( + `${PAYMENT_SERVICE_URL}/transfer/id/${user.id}/amount/10000`, + requestOptions + ) + let result = await response.json() + setPayment(result) + console.log(result) + } + + let placeOrder = async () => { + console.log('placeOrder', product) + const requestOptions = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + productName: product.PRODUCT_NAME, + price: product.PRICE, + }), + } + let response = await fetch(`${ORDER_SERVICE_URL}/create/id/${user.id}`, requestOptions) + let result = await response.json() + setOrder(result) + console.log(result) + } + let handleReset = () => { + setUser() + setPayment() + setOrder() + setProduct() + } + let setUrl = (e) => setSignozUrl(e.target.value) + let openSignoz = () => window.open(signozUrl) + return ( +
+ + + +

Make sure signoz is running on {signozUrl}

+ + + + {user && ( +
+ + + +
+ )} + {payment && ( +
+ + + {product && } + {order && ( +
+ +

Order Placed!

+
+ )} +
+ )} +
+ ) +} + +ReactDOM.render(, document.getElementById('app')) diff --git a/user-service/src/main/java/com/signoz/userservice/controller/UserController.java b/user-service/src/main/java/com/signoz/userservice/controller/UserController.java index cc5a7ea..d9bb674 100644 --- a/user-service/src/main/java/com/signoz/userservice/controller/UserController.java +++ b/user-service/src/main/java/com/signoz/userservice/controller/UserController.java @@ -12,6 +12,7 @@ @RestController +@CrossOrigin(origins = "*") public class UserController { @Autowired diff --git a/user-service/src/main/java/com/signoz/userservice/entity/Users.java b/user-service/src/main/java/com/signoz/userservice/entity/Users.java index ce73019..dc1e728 100644 --- a/user-service/src/main/java/com/signoz/userservice/entity/Users.java +++ b/user-service/src/main/java/com/signoz/userservice/entity/Users.java @@ -15,7 +15,7 @@ @AllArgsConstructor @NoArgsConstructor @Entity -@Table(name = "USERS") +@Table(name = "users_tbl") @EntityListeners(AuditingEntityListener.class) public class Users {