Commit adb72695 authored by snamdeo's avatar snamdeo

Commiting after adding Valet changes

parent 114b63c3
package com.altimetrik.poc;
import com.altimetrik.poc.dto.Customer;
import com.altimetrik.poc.repository.UserLoggedInRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.Random;
import static com.altimetrik.poc.dto.Customer.refer;
@SpringBootApplication
public class ShoppingCartAppApplication {
......@@ -10,4 +18,18 @@ public class ShoppingCartAppApplication {
SpringApplication.run(ShoppingCartAppApplication.class, args);
}
@Bean
public CommandLineRunner demoData(UserLoggedInRepository userLoggedInRepository) {
return args -> {
Random random = new Random();
Customer c = new Customer();
refer = random.nextInt(1000);
c.setReference(refer);
c.setFirstName("Ram"); c.setLastName("Namdeo");
c.setEmailId("shishirnamdeo220@gmail.com");
c.setValetAmount(0);
userLoggedInRepository.save(c);
};
}
}
......@@ -22,7 +22,7 @@ public class FetchProductDataController {
@GetMapping("/getAllProducts")
@CrossOrigin(origins="http://localhost:3000/")
public ResponseEntity<List<ProductDetails>> getAllProducts() throws SQLException, IOException {
public ResponseEntity<List<ProductDetails>> getAllProducts() {
List<ProductDetails> products = fetchProductsRepository.findAll();
System.out.println(products);
return ResponseEntity.ok(products);
......
......@@ -16,7 +16,7 @@ public class ShoppingCartController {
@Autowired
ShoppingCartServices shoppingCartServices;
@GetMapping("/getProducts")
@GetMapping("/getOrderDetails")
public ResponseEntity<List<OrderDetails>> getProducts(){
List<OrderDetails> products = shoppingCartServices.getProducts();
......@@ -24,22 +24,11 @@ public class ShoppingCartController {
}
@DeleteMapping("/removeProducts")
public void removeProducts(@RequestBody OrderDetails p){
shoppingCartServices.removeProducts(p);
}
@PostMapping ("/addProducts")
@PostMapping ("/addOrderDetails")
@CrossOrigin(origins="http://localhost:3000/")
public void addProducts(@RequestBody OrderDetails p){
shoppingCartServices.addProducts(p);
}
@PutMapping("/updateProducts")
public void updateProducts(@RequestBody OrderDetails p){
shoppingCartServices.updateProduct(p);
}
}
package com.altimetrik.poc.controller;
import com.altimetrik.poc.dto.Customer;
import com.altimetrik.poc.dto.NewValetAmout;
import com.altimetrik.poc.repository.UserLoggedInRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -18,4 +19,19 @@ public class UserDataController {
userLoggedInRepository.save(p);
}
@GetMapping("/getUserValetAmount")
@CrossOrigin(origins="http://localhost:3000/")
public Integer getUserValetAmount(){
Customer customer = userLoggedInRepository.findByReference(Customer.refer);
return customer.getValetAmount();
}
@PutMapping("/updateValetAmount")
@CrossOrigin(origins="http://localhost:3000/")
public void updateValetAmount(@RequestBody NewValetAmout newValetAmt){
Customer customer = userLoggedInRepository.findByReference(Customer.refer);
customer.setValetAmount(Integer.parseInt(newValetAmt.getNewValetAmt()));
userLoggedInRepository.save(customer);
}
}
......@@ -18,25 +18,27 @@ public class Customer {
@Id
@GeneratedValue
private Integer id;
private Integer userId;
private String firstName;
private String lastName;
private String emailId;
private Integer reference;
public static int refer = 0;
@OneToMany(
mappedBy = "customer",
cascade = CascadeType.ALL
)
private List<OrderDetails> orderDetails = new ArrayList<OrderDetails>();
@OneToOne
@JoinColumn(name = "customer_valet_details_id")
private CustomerValetDetails customerValetDetails;
private Integer valetAmount ;
public Customer(Integer userId, String firstName, String lastName, String emailId) {
this.userId = userId;
public Customer(String firstName, String lastName, String emailId,Integer valetAmount) {
this.firstName = firstName;
this.lastName = lastName;
this.emailId = emailId;
this.valetAmount = valetAmount;
}
}
......@@ -5,19 +5,10 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "UserdataDetails")
@Entity
public class CustomerValetDetails {
@Id
@GeneratedValue
private Integer id;
private Integer valetAmount;
@OneToOne(mappedBy = "customerValetDetails")
private Customer customer;
}
\ No newline at end of file
public class NewValetAmout {
private String newValetAmt;
}
......@@ -23,7 +23,6 @@ public class OrderDetails {
private Integer itemsPrice;
private Integer[] productIds;
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer;
......
......@@ -5,6 +5,6 @@ import com.altimetrik.poc.dto.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserLoggedInRepository extends JpaRepository<Customer,Integer> {
Customer findByReference(Integer reference);
}
......@@ -9,8 +9,5 @@ public interface ShoppingCartServices {
public void addProducts(OrderDetails p);
public void removeProducts(OrderDetails p);
public void updateProduct(OrderDetails p);
}
package com.altimetrik.poc.services;
import com.altimetrik.poc.dto.Customer;
import com.altimetrik.poc.dto.OrderDetails;
import com.altimetrik.poc.repository.ShoppingCartRepository;
import com.altimetrik.poc.repository.UserLoggedInRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional
public class ShoppingCartServicesImpl implements ShoppingCartServices{
@Autowired
ShoppingCartRepository shoppingCartRepository;
List<OrderDetails> product = new ArrayList<>();
@Autowired
UserLoggedInRepository userLoggedInRepository;
public List<OrderDetails> getProducts(){
return shoppingCartRepository.findAll();
}
public void addProducts(OrderDetails p){
Customer customer = userLoggedInRepository.findByReference(Customer.refer);
p.setCustomer(customer);
List<OrderDetails> orderDetails = new ArrayList<OrderDetails>();
orderDetails.add(p);
customer.setOrderDetails(orderDetails);
shoppingCartRepository.save(p);
}
public void removeProducts(OrderDetails p){
product.remove(p);
}
public void updateProduct(OrderDetails p){
product.remove(p);
}
}
......@@ -3,6 +3,6 @@ spring.datasource.url= jdbc:mysql://localhost:3306/shopping_cart_db
spring.datasource.username=root
spring.datasource.password=Qazwsx@2022#
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
server.port=9090
\ No newline at end of file
package com.altimetrik.poc.controller;
import com.altimetrik.poc.dto.Customer;
import com.altimetrik.poc.repository.UserLoggedInRepository;
import org.junit.jupiter.api.Test;
......@@ -23,7 +21,7 @@ public class UserDataControllerTest {
@Test
public void removeProducts(){
Customer c = new Customer(233, "Shishir", "Namdeo","shishirnamdeo220@gmaik.com");
Customer c = new Customer("Shishir", "Namdeo","shishirnamdeo220@gmaik.com",0);
userDataController.addUser(c);
verify(userLoggedInRepository,times(1)).save(c);
......
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