Browse Source

flushing data to order db is done but quantity is not added

gauravfullcomponent
Gaurav Daharia 4 years ago
parent
commit
0e7872f5ef
16 changed files with 351 additions and 45 deletions
  1. 8
      Angular-UrbanBazaar/proxy.config.json
  2. 9
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
  3. 3
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
  4. 55
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts
  5. 21
      Angular-UrbanBazaar/src/app/models/orders.ts
  6. 15
      Angular-UrbanBazaar/src/app/services/orders.service.ts
  7. 22
      UB_ProductServiceProxy/pom.xml
  8. 50
      UB_ProductServiceProxy/src/main/java/com/example/MessageConfig/MessaageConfig.java
  9. 2
      UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java
  10. 56
      UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/controller/OrderController.java
  11. 73
      UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/Order.java
  12. 39
      UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/model/OrderStatus.java
  13. 16
      UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/repository/OrderRepository.java
  14. 14
      UB_ProductServiceProxy/src/main/resources/application.properties
  15. 12
      grosery_db.sql
  16. 1
      springboot-rabbitmq-example

8
Angular-UrbanBazaar/proxy.config.json

@ -6,14 +6,6 @@
"/user":{ "/user":{
"target":"http://10.3.117.5:8011", "target":"http://10.3.117.5:8011",
"secure":false "secure":false
},
"/orders":{
"target":"http://10.3.117.7:8009",
"secure":false
},
"/cart":{
"target":"http://10.3.117.7:8010",
"secure":false
} }
} }

9
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css

@ -16,6 +16,15 @@
align-items: center; align-items: center;
} }
.placeorder{
position: absolute;
bottom: 2px;
right: 694px;
border-radius: 15px;
border-color:antiquewhite ;
background-color: beige;
padding: 1%;
}
.table{ .table{
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
} }

3
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html

@ -20,6 +20,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<button class="logout" (click)=logout() class="CartButtons">log out</button>
<button (click)=logout() class="CartButtons">log out</button>
<button class="placeorder" (click)=place()>Place order</button>
</div> </div>
</ng-container> </ng-container>

55
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts

@ -1,7 +1,10 @@
import { unescapeIdentifier } from '@angular/compiler'; import { unescapeIdentifier } from '@angular/compiler';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; 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 { CartService } from 'src/app/services/cart.service';
import { OrdersService } from 'src/app/services/orders.service';
import { UserService } from 'src/app/services/user.service'; import { UserService } from 'src/app/services/user.service';
@Component({ @Component({
@ -11,13 +14,35 @@ import { UserService } from 'src/app/services/user.service';
}) })
export class CheckoutComponent implements OnInit { export class CheckoutComponent implements OnInit {
public cartdetails: any[] = []; public cartdetails: any[] = [];
public orderdetails: any[]=[];
public grandTotal = 0; 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); public uid = (this.userservice.currentUser.userid);
uid1 = this.uid.toString() 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() { logout() {
@ -27,7 +52,14 @@ export class CheckoutComponent implements OnInit {
this.cartdetails.splice(index); 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 { ngOnInit(): void {
@ -35,9 +67,24 @@ export class CheckoutComponent implements OnInit {
.subscribe(res => { .subscribe(res => {
this.cartdetails = res; this.cartdetails = res;
this.cartdetails.forEach((i, index) => { 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.grandTotal += i.productprice;
}) })
}) })
}
// this.orderservice.showOrder().subscribe(res=>{
// this.orderdetails = res;
// // this.orderdetails.forEach((i,index)=>{
// // this.grandTotal+=i.productprice
// // })
// })
}
} }

21
Angular-UrbanBazaar/src/app/models/orders.ts

@ -1,20 +1,9 @@
export class Orders { 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() {} constructor() {}
} }

15
Angular-UrbanBazaar/src/app/services/orders.service.ts

@ -7,19 +7,22 @@ import { Orders } from '../models/orders';
providedIn: 'root', providedIn: 'root',
}) })
export class OrdersService { export class OrdersService {
private _url: String = 'http://localhost:8009/orders';
private _url: String = 'http://localhost:8014/products';
constructor(private _http: HttpClient) {} constructor(private _http: HttpClient) {}
public addOrder(order: Orders) { public addOrder(order: Orders) {
this._http.post(this._url + '/addOrder', order);
return this._http.post(this._url + '/bookorder', order);
} }
public findOrder(id: number): Observable<Orders> {
return this._http.get<Orders>(this._url + '/findOrder' + id);
public showOrder():Observable<Orders[]>
{
return this._http.get<Orders[]>(this._url+'/showOrder');
} }
public findOrdersByUser(id: number): Observable<Orders[]> {
return this._http.get<Orders[]>(this._url + '/findOrdersByUser' + id);
public deleteAll()
{
return this._http.delete<any>(this._url+"/deleteAll")
} }
} }

22
UB_ProductServiceProxy/pom.xml

@ -32,6 +32,14 @@
<scope>runtime</scope> <scope>runtime</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
@ -41,6 +49,20 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

50
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;
}
}

2
UB_ProductServiceProxy/src/main/java/com/example/urbanbazaar/UbProductServiceProxyApplication.java

@ -1,9 +1,11 @@
package com.example.urbanbazaar; package com.example.urbanbazaar;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@EnableAutoConfiguration()
public class UbProductServiceProxyApplication { public class UbProductServiceProxyApplication {
public static void main(String[] args) { public static void main(String[] args) {

56
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 List<Order>allOrder()
{
return repo.findAll();
}
@DeleteMapping("/deleteOrder")
public void deleteAll()
{
repo.deleteAll();
}
}

73
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() {
}
}

39
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 + "]";
}
}

16
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<Order, Integer>{
// @Query(value="select * from Order o where o.userid=:userid", nativeQuery=true)
// List<Order>showAll(@Param("userid") int userid);
}

14
UB_ProductServiceProxy/src/main/resources/application.properties

@ -1,11 +1,19 @@
server.port=8014 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.username=testuser
spring.datasource.password=Password123 spring.datasource.password=Password123
server.servlet.context-path=/products 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.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
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

12
grosery_db.sql

@ -89,15 +89,13 @@ insert into product values (1007, "Eggs - Regular (12)", 76,
select * from product; select * from product;
-- Orders Table Schema -- Orders Table Schema
CREATE TABLE IF NOT EXISTS `orders` ( CREATE TABLE IF NOT EXISTS `orders` (
`userid` int(11) NOT NULL,
`orderid` int(11) NOT NULL AUTO_INCREMENT, `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`) FOREIGN KEY (`userid`) REFERENCES users(`userid`)
); );

1
springboot-rabbitmq-example

@ -0,0 +1 @@
Subproject commit 10a0271fcba7f90b09523ad74703297c45b2b620
Loading…
Cancel
Save