From 0e7872f5efb0f33b05fda406f4fe5fce18860c73 Mon Sep 17 00:00:00 2001
From: Gaurav Daharia <59254@hexaware.com>
Date: Tue, 28 Sep 2021 16:58:00 +0530
Subject: [PATCH] flushing data to order db is done but quantity is not added
---
Angular-UrbanBazaar/proxy.config.json | 8 --
.../checkout/checkout.component.css | 9 +++
.../checkout/checkout.component.html | 3 +-
.../components/checkout/checkout.component.ts | 55 +++++++++++++-
Angular-UrbanBazaar/src/app/models/orders.ts | 21 ++----
.../src/app/services/orders.service.ts | 15 ++--
UB_ProductServiceProxy/pom.xml | 22 ++++++
.../example/MessageConfig/MessaageConfig.java | 50 +++++++++++++
.../UbProductServiceProxyApplication.java | 2 +
.../controller/OrderController.java | 56 ++++++++++++++
.../com/example/urbanbazaar/model/Order.java | 73 +++++++++++++++++++
.../urbanbazaar/model/OrderStatus.java | 39 ++++++++++
.../repository/OrderRepository.java | 16 ++++
.../src/main/resources/application.properties | 14 +++-
grosery_db.sql | 12 ++-
springboot-rabbitmq-example | 1 +
16 files changed, 351 insertions(+), 45 deletions(-)
create mode 100644 UB_ProductServiceProxy/src/main/java/com/example/MessageConfig/MessaageConfig.java
create mode 100644 UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/controller/OrderController.java
create mode 100644 UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/Order.java
create mode 100644 UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/OrderStatus.java
create mode 100644 UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/repository/OrderRepository.java
create mode 160000 springboot-rabbitmq-example
diff --git a/Angular-UrbanBazaar/proxy.config.json b/Angular-UrbanBazaar/proxy.config.json
index 7597d28..3807cc5 100644
--- a/Angular-UrbanBazaar/proxy.config.json
+++ b/Angular-UrbanBazaar/proxy.config.json
@@ -6,14 +6,6 @@
"/user":{
"target":"http://10.3.117.5:8011",
"secure":false
- },
- "/orders":{
- "target":"http://10.3.117.7:8009",
- "secure":false
- },
- "/cart":{
- "target":"http://10.3.117.7:8010",
- "secure":false
}
}
\ No newline at end of file
diff --git a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
index a611832..a6e0c61 100644
--- a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
+++ b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
@@ -16,6 +16,15 @@
align-items: center;
}
+.placeorder{
+ position: absolute;
+ bottom: 2px;
+ right: 694px;
+ border-radius: 15px;
+ border-color:antiquewhite ;
+ background-color: beige;
+ padding: 1%;
+}
.table{
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
diff --git a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
index ad43022..7bc7858 100644
--- a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
+++ b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
@@ -20,6 +20,7 @@
-
+
+
\ No newline at end of file
diff --git a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts
index 6225c98..d9b085f 100644
--- a/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts
+++ b/Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts
@@ -1,7 +1,10 @@
import { unescapeIdentifier } from '@angular/compiler';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
+import { Observable } from 'rxjs';
+import { Orders } from 'src/app/models/orders';
import { CartService } from 'src/app/services/cart.service';
+import { OrdersService } from 'src/app/services/orders.service';
import { UserService } from 'src/app/services/user.service';
@Component({
@@ -11,13 +14,35 @@ import { UserService } from 'src/app/services/user.service';
})
export class CheckoutComponent implements OnInit {
public cartdetails: any[] = [];
+ public orderdetails: any[]=[];
public grandTotal = 0;
- constructor(private cartservice: CartService, private router: Router,private userservice:UserService) {
-
+ constructor(private cartservice: CartService, private router: Router,private userservice:UserService, private orderservice:OrdersService) {
+ // this.orderdetails = this.orderservice.showOrder();
}
public uid = (this.userservice.currentUser.userid);
uid1 = this.uid.toString()
+ place()
+ {
+ // this.orderservice.deleteAll().subscribe(b=>{
+ // this.orderdetails.forEach((i,index)=>{
+ // this.orderdetails.splice(index);
+ // })
+ // })
+
+ // this.orderservice.deleteAll().subscribe()
+ alert("your order have been placed for uid:"+this.uid1+"\n"+"Visit Again !")
+
+
+ // this.router.navigateByUrl("/");
+ this.cartservice.deleteAll().subscribe(b => {
+ this.cartdetails.forEach((i, index) => {
+ this.cartdetails.splice(index);
+ })
+ });
+ this.router.navigateByUrl("/");
+
+ }
logout() {
@@ -27,7 +52,14 @@ export class CheckoutComponent implements OnInit {
this.cartdetails.splice(index);
})
});
- alert("your order have been placed for uid:"+this.uid1+"\n"+"Visit Again !")
+
+ this.orderservice.deleteAll().subscribe(b=>{
+ this.orderdetails.forEach((i,index)=>{
+ this.orderdetails.splice(index);
+ })
+ })
+
+
}
ngOnInit(): void {
@@ -35,9 +67,24 @@ export class CheckoutComponent implements OnInit {
.subscribe(res => {
this.cartdetails = res;
this.cartdetails.forEach((i, index) => {
+ //console.log(i.productprice,i.userid,i.productname);
+ let order = new Orders();
+ order.productname = i.productname
+ order.productprice = i.productprice
+ order.userid = i.userid;
+ this.orderservice.addOrder(order).subscribe();
this.grandTotal += i.productprice;
})
})
- }
+
+
+ // this.orderservice.showOrder().subscribe(res=>{
+ // this.orderdetails = res;
+ // // this.orderdetails.forEach((i,index)=>{
+ // // this.grandTotal+=i.productprice
+ // // })
+ // })
+
+ }
}
diff --git a/Angular-UrbanBazaar/src/app/models/orders.ts b/Angular-UrbanBazaar/src/app/models/orders.ts
index cbf707c..d6c08b4 100644
--- a/Angular-UrbanBazaar/src/app/models/orders.ts
+++ b/Angular-UrbanBazaar/src/app/models/orders.ts
@@ -1,20 +1,9 @@
export class Orders {
- public orderid: number;
- public orderuserid: number;
- public orderamount: number;
- public ordershipaddress: string;
- public ordershipaddress2: string;
- public ordercity: string;
- public orderzip: string;
- public orderstate: string;
- public ordercountry: string;
- public orderphone: string;
- public ordershippingcost: number;
- public ordertax: number;
- public orderemail: string;
- public orderdate: Date;
- public ordershipped: string;
- public ordertrackingnumber: string;
+ orderid:number;
+ userid:number;
+ productname:string;
+ productprice:string;
+
constructor() {}
}
diff --git a/Angular-UrbanBazaar/src/app/services/orders.service.ts b/Angular-UrbanBazaar/src/app/services/orders.service.ts
index 1b24bc6..0a57ef2 100644
--- a/Angular-UrbanBazaar/src/app/services/orders.service.ts
+++ b/Angular-UrbanBazaar/src/app/services/orders.service.ts
@@ -7,19 +7,22 @@ import { Orders } from '../models/orders';
providedIn: 'root',
})
export class OrdersService {
- private _url: String = 'http://localhost:8009/orders';
+ private _url: String = 'http://localhost:8014/products';
constructor(private _http: HttpClient) {}
public addOrder(order: Orders) {
- this._http.post(this._url + '/addOrder', order);
+ return this._http.post(this._url + '/bookorder', order);
}
- public findOrder(id: number): Observable {
- return this._http.get(this._url + '/findOrder' + id);
+ public showOrder():Observable
+ {
+ return this._http.get(this._url+'/showOrder');
}
- public findOrdersByUser(id: number): Observable {
- return this._http.get(this._url + '/findOrdersByUser' + id);
+ public deleteAll()
+ {
+ return this._http.delete(this._url+"/deleteAll")
}
+
}
diff --git a/UB_ProductServiceProxy/pom.xml b/UB_ProductServiceProxy/pom.xml
index 0abce40..4bd566f 100644
--- a/UB_ProductServiceProxy/pom.xml
+++ b/UB_ProductServiceProxy/pom.xml
@@ -32,6 +32,14 @@
runtime
true
+
+
+ org.springframework.amqp
+ spring-rabbit-test
+ test
+
+
+
mysql
mysql-connector-java
@@ -41,6 +49,20 @@
org.springframework.boot
spring-boot-starter-test
test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
+
+
+ org.springframework.amqp
+ spring-amqp
+
+
+ org.springframework.amqp
+ spring-rabbit
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/MessageConfig/MessaageConfig.java b/UB_ProductServiceProxy/src/main/java/com/example/MessageConfig/MessaageConfig.java
new file mode 100644
index 0000000..b0aca3b
--- /dev/null
+++ b/UB_ProductServiceProxy/src/main/java/com/example/MessageConfig/MessaageConfig.java
@@ -0,0 +1,50 @@
+package com.example.MessageConfig;
+
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.core.TopicExchange;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
+import org.springframework.amqp.support.converter.MessageConverter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MessaageConfig {
+
+
+ public static final String QUEUE = "ub_queue";
+ public static final String EXCHANGE = "ub_exchange";
+ public static final String ROUTING_KEY = "ub_routingKey";
+
+ @Bean
+ public Queue queue() {
+ return new Queue(QUEUE);
+ }
+
+ @Bean
+ public TopicExchange exchange() {
+ return new TopicExchange(EXCHANGE);
+ }
+
+ @Bean
+ public Binding binding(Queue queue, TopicExchange exchange) {
+ return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY);
+ }
+
+ @Bean
+ public MessageConverter converter() {
+ return new Jackson2JsonMessageConverter();
+ }
+
+ @Bean
+ public AmqpTemplate template(ConnectionFactory connectionFactory) {
+ final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
+ rabbitTemplate.setMessageConverter(converter());
+ return rabbitTemplate;
+ }
+
+}
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java
index ad41047..0d280ea 100644
--- a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java
+++ b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java
@@ -1,9 +1,11 @@
package com.example.urbanbazaar;
import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
+@EnableAutoConfiguration()
public class UbProductServiceProxyApplication {
public static void main(String[] args) {
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/controller/OrderController.java b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/controller/OrderController.java
new file mode 100644
index 0000000..a80989b
--- /dev/null
+++ b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/controller/OrderController.java
@@ -0,0 +1,56 @@
+package com.example.urbanbazaar.controller;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.example.MessageConfig.MessaageConfig;
+import com.example.urbanbazaar.model.Order;
+import com.example.urbanbazaar.model.OrderStatus;
+import com.example.urbanbazaar.repository.OrderRepository;
+
+
+
+@RestController
+//@RequestMapping("/order")
+public class OrderController {
+
+
+ @Autowired
+ private RabbitTemplate template;
+
+ @Autowired
+ private OrderRepository repo;
+
+
+ @PostMapping("/bookorder")
+ public String bookOrder(@RequestBody Order order) {
+ repo.save(order);
+ OrderStatus orderStatus = new OrderStatus(order, "PROCESS", "orderedDone!");
+ template.convertAndSend(MessaageConfig.EXCHANGE, MessaageConfig.ROUTING_KEY, orderStatus);
+ return "Success !!";
+ }
+
+ @GetMapping("/showOrder")
+ public ListallOrder()
+ {
+ return repo.findAll();
+ }
+
+ @DeleteMapping("/deleteOrder")
+ public void deleteAll()
+ {
+ repo.deleteAll();
+ }
+
+}
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/Order.java b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/Order.java
new file mode 100644
index 0000000..276ff39
--- /dev/null
+++ b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/Order.java
@@ -0,0 +1,73 @@
+package com.example.urbanbazaar.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "orders")
+public class Order implements Serializable {
+
+ @Id
+ @GeneratedValue
+ private int orderid;
+ private int userid;
+ private String productname;
+ private float productprice;
+
+ public int getOrderid() {
+ return orderid;
+ }
+
+ public void setOrderid(int orderid) {
+ this.orderid = orderid;
+ }
+
+ public int getUserid() {
+ return userid;
+ }
+
+ public void setUserid(int userid) {
+ this.userid = userid;
+ }
+
+ public String getProductname() {
+ return productname;
+ }
+
+ public void setProductname(String productname) {
+ this.productname = productname;
+ }
+
+ public float getProductprice() {
+ return productprice;
+ }
+
+ public void setProductprice(float productprice) {
+ this.productprice = productprice;
+ }
+
+ public Order(int orderid, int userid, String productname, float productprice) {
+
+ this.orderid = orderid;
+ this.userid = userid;
+ this.productname = productname;
+ this.productprice = productprice;
+ }
+
+
+
+ @Override
+ public String toString() {
+ return "Order [orderid=" + orderid + ", userid=" + userid + ", productname=" + productname + ", productprice="
+ + productprice + "]";
+ }
+
+ public Order() {
+
+ }
+
+}
\ No newline at end of file
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/OrderStatus.java b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/OrderStatus.java
new file mode 100644
index 0000000..8d4002b
--- /dev/null
+++ b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/OrderStatus.java
@@ -0,0 +1,39 @@
+package com.example.urbanbazaar.model;
+
+import java.io.Serializable;
+
+public class OrderStatus implements Serializable {
+ private Order order;
+ private String status;//progress,completed
+ private String message;
+ public Order getOrder() {
+ return order;
+ }
+ public void setOrder(Order order) {
+ this.order = order;
+ }
+ public String getStatus() {
+ return status;
+ }
+ public void setStatus(String status) {
+ this.status = status;
+ }
+ public String getMessage() {
+ return message;
+ }
+ public void setMessage(String message) {
+ this.message = message;
+ }
+ public OrderStatus(Order order, String status, String message) {
+
+ this.order = order;
+ this.status = status;
+ this.message = message;
+ }
+ @Override
+ public String toString() {
+ return "OrderStatus [order=" + order + ", status=" + status + ", message=" + message + "]";
+ }
+
+
+}
diff --git a/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/repository/OrderRepository.java b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/repository/OrderRepository.java
new file mode 100644
index 0000000..985a30f
--- /dev/null
+++ b/UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/repository/OrderRepository.java
@@ -0,0 +1,16 @@
+package com.example.urbanbazaar.repository;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+
+import com.example.urbanbazaar.model.Order;
+
+public interface OrderRepository extends JpaRepository{
+
+// @Query(value="select * from Order o where o.userid=:userid", nativeQuery=true)
+// ListshowAll(@Param("userid") int userid);
+
+}
diff --git a/UB_ProductServiceProxy/src/main/resources/application.properties b/UB_ProductServiceProxy/src/main/resources/application.properties
index 503fe8e..5743edb 100644
--- a/UB_ProductServiceProxy/src/main/resources/application.properties
+++ b/UB_ProductServiceProxy/src/main/resources/application.properties
@@ -1,11 +1,19 @@
server.port=8014
-spring.datasource.url=jdbc:mysql://10.3.117.7:3306/grocery_db?createDatabaseIfNotExist=true
+spring.datasource.url=jdbc:mysql://localhost:3306/grocery_db?createDatabaseIfNotExist=true
spring.datasource.username=testuser
spring.datasource.password=Password123
server.servlet.context-path=/products
-#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
+#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
+#hibernate.dialect.storage_engine=innodb
+#spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
-spring.jackson.serialization.fail-on-empty-beans=false
\ No newline at end of file
+spring.jackson.serialization.fail-on-empty-beans=false
+
+spring.rabbitmq.port=5672
+spring.rabbitmq.host=labs4.koteshwar.com
+
+spring.rabbitmq.username=guest
+spring.rabbitmq.password=guest
\ No newline at end of file
diff --git a/grosery_db.sql b/grosery_db.sql
index 7e37d17..34ae3f3 100644
--- a/grosery_db.sql
+++ b/grosery_db.sql
@@ -89,15 +89,13 @@ insert into product values (1007, "Eggs - Regular (12)", 76,
select * from product;
-- Orders Table Schema
+
CREATE TABLE IF NOT EXISTS `orders` (
+ `userid` int(11) NOT NULL,
`orderid` int(11) NOT NULL AUTO_INCREMENT,
- `userid` int(11) NOT NULL,
- `orderamount` float NOT NULL,
- `ordershippingcost` float NOT NULL,
- `orderdate` date not null,
- `orderstatus` varchar(100) not null,
- `ordertrackingnumber` varchar(80) DEFAULT NULL,
- PRIMARY KEY (`orderiD`),
+ `productname` varchar(100) NOT NULL,
+ `productprice` float NOT NULL,
+ PRIMARY KEY (`orderid`),
FOREIGN KEY (`userid`) REFERENCES users(`userid`)
);
diff --git a/springboot-rabbitmq-example b/springboot-rabbitmq-example
new file mode 160000
index 0000000..10a0271
--- /dev/null
+++ b/springboot-rabbitmq-example
@@ -0,0 +1 @@
+Subproject commit 10a0271fcba7f90b09523ad74703297c45b2b620