Commit 485d0c2b authored by snamdeo's avatar snamdeo

commiting the new chaanges with my sql server

parent 13e167d7
package com.poc.altimetrik; package com.poc.altimetrik;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.repository.UserLoggedInRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.Random;
import static com.poc.altimetrik.dto.Customer.refer;
@SpringBootApplication @SpringBootApplication
public class FoodDeliveryApplication { public class FoodDeliveryApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(FoodDeliveryApplication.class, args); SpringApplication.run(FoodDeliveryApplication.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);
};
} }
} }
package com.poc.altimetrik.controller; package com.poc.altimetrik.controller;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.dto.OrderDetails; import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.services.FoodCartServices; import com.poc.altimetrik.services.FoodCartServices;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
package com.poc.altimetrik.controller; package com.poc.altimetrik.controller;
import com.poc.altimetrik.dto.Customer; import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.dto.NewValetAmout;
import com.poc.altimetrik.repository.UserLoggedInRepository; import com.poc.altimetrik.repository.UserLoggedInRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -13,8 +14,22 @@ public class UserDataController { ...@@ -13,8 +14,22 @@ public class UserDataController {
@PostMapping("/userLoggedIn") @PostMapping("/userLoggedIn")
@CrossOrigin(origins="http://localhost:3008/") @CrossOrigin(origins="http://localhost:3008/")
public void addUser(@RequestBody Customer p){ public void addUser(@RequestBody Customer p){
System.out.println(p);
userLoggedInRepository.save(p); userLoggedInRepository.save(p);
} }
@GetMapping("/getUserValetAmount")
@CrossOrigin(origins="http://localhost:3008/")
public Integer getUserValetAmount(){
Customer customer = userLoggedInRepository.findByReference(Customer.refer);
return customer.getValetAmount();
}
@PutMapping("/updateValetAmount")
@CrossOrigin(origins="http://localhost:3008/")
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 { ...@@ -18,25 +18,27 @@ public class Customer {
@Id @Id
@GeneratedValue @GeneratedValue
private Integer id; private Integer id;
private Integer userId;
private String firstName; private String firstName;
private String lastName; private String lastName;
private String emailId; private String emailId;
private Integer reference;
public static int refer = 0;
@OneToMany( @OneToMany(
mappedBy = "customer", mappedBy = "customer",
cascade = CascadeType.ALL cascade = CascadeType.ALL
) )
private List<OrderDetails> orderDetails = new ArrayList<OrderDetails>(); private List<OrderDetails> orderDetails = new ArrayList<OrderDetails>();
@OneToOne private Integer valetAmount ;
@JoinColumn(name = "customer_valet_details_id")
private CustomerValetDetails customerValetDetails;
public Customer(Integer userId, String firstName, String lastName, String emailId) { public Customer(String firstName, String lastName, String emailId,Integer valetAmount) {
this.userId = userId;
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
this.emailId = emailId; this.emailId = emailId;
this.valetAmount = valetAmount;
} }
} }
...@@ -5,19 +5,10 @@ import lombok.Builder; ...@@ -5,19 +5,10 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data @Data
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Table(name = "UserdataDetails") public class NewValetAmout {
@Entity private String newValetAmt;
public class CustomerValetDetails { }
@Id
@GeneratedValue
private Integer id;
private Integer valetAmount;
@OneToOne(mappedBy = "customerValetDetails")
private Customer customer;
}
\ No newline at end of file
...@@ -21,9 +21,9 @@ public class OrderDetails { ...@@ -21,9 +21,9 @@ public class OrderDetails {
private Integer shippingPrice; private Integer shippingPrice;
private Integer totalPrice; private Integer totalPrice;
private Integer itemsPrice; private Integer itemsPrice;
private Integer reference;
private Integer[] productIds; private Integer[] productIds;
@ManyToOne @ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer; private Customer customer;
......
...@@ -3,7 +3,9 @@ package com.poc.altimetrik.repository; ...@@ -3,7 +3,9 @@ package com.poc.altimetrik.repository;
import com.poc.altimetrik.dto.Customer; import com.poc.altimetrik.dto.Customer;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface UserLoggedInRepository extends JpaRepository<Customer,Integer> { import java.util.List;
public interface UserLoggedInRepository extends JpaRepository<Customer,Integer> {
Customer findByReference(Integer reference);
} }
package com.poc.altimetrik.services; package com.poc.altimetrik.services;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.dto.OrderDetails; import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.repository.FoodeliveryRepository; import com.poc.altimetrik.repository.FoodeliveryRepository;
import com.poc.altimetrik.repository.UserLoggedInRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
@Transactional
public class FoodCartServicesImpl implements FoodCartServices { public class FoodCartServicesImpl implements FoodCartServices {
@Autowired @Autowired
FoodeliveryRepository foodeliveryRepository; FoodeliveryRepository foodeliveryRepository;
List<OrderDetails> product = new ArrayList<>();
@Autowired
UserLoggedInRepository userLoggedInRepository;
public List<OrderDetails> getProducts(){ public List<OrderDetails> getProducts(){
return foodeliveryRepository.findAll(); return foodeliveryRepository.findAll();
} }
public void addProducts(OrderDetails p){ public void addProducts(OrderDetails p){
// System.out.println(c); Customer customer = userLoggedInRepository.findByReference(Customer.refer);
p.setCustomer(customer);
List<OrderDetails> orderDetails = new ArrayList<OrderDetails>();
orderDetails.add(p);
customer.setOrderDetails(orderDetails);
foodeliveryRepository.save(p); foodeliveryRepository.save(p);
} }
......
...@@ -3,5 +3,5 @@ spring.datasource.url= jdbc:mysql://localhost:3306/shishirdb ...@@ -3,5 +3,5 @@ spring.datasource.url= jdbc:mysql://localhost:3306/shishirdb
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=Qazwsx@2022# spring.datasource.password=Qazwsx@2022#
spring.jpa.show-sql=true 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 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
\ No newline at end of file
...@@ -26,7 +26,7 @@ class FoodCartControllerTest { ...@@ -26,7 +26,7 @@ class FoodCartControllerTest {
public void getProducts(){ public void getProducts(){
when(foodCartServices.getProducts()).thenReturn(Stream.of( when(foodCartServices.getProducts()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList())); new OrderDetails(300,3761,0,0,42,342,667,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals("200 OK",foodCartController.getProducts().getStatusCode().toString()); assertEquals("200 OK",foodCartController.getProducts().getStatusCode().toString());
...@@ -34,7 +34,8 @@ class FoodCartControllerTest { ...@@ -34,7 +34,8 @@ class FoodCartControllerTest {
@Test @Test
public void addProducts(){ public void addProducts(){
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer()); OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454,667, new Integer[43], new Customer());
Customer c = new Customer();
foodCartController.addProducts(pd); foodCartController.addProducts(pd);
verify(foodCartServices,times(1)).addProducts(pd); verify(foodCartServices,times(1)).addProducts(pd);
} }
......
...@@ -22,7 +22,7 @@ public class UserDataControllerTest { ...@@ -22,7 +22,7 @@ public class UserDataControllerTest {
@Test @Test
public void removeProducts(){ 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); userDataController.addUser(c);
verify(userLoggedInRepository,times(1)).save(c); verify(userLoggedInRepository,times(1)).save(c);
......
...@@ -34,7 +34,7 @@ public class FoodCartServicesTest { ...@@ -34,7 +34,7 @@ public class FoodCartServicesTest {
when(foodeliveryRepository.findAll()).thenReturn(Stream.of( when(foodeliveryRepository.findAll()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList())); new OrderDetails(300,3761,0,0,42,342,667,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals(1,foodCartServices.getProducts().size()); assertEquals(1,foodCartServices.getProducts().size());
...@@ -44,7 +44,7 @@ public class FoodCartServicesTest { ...@@ -44,7 +44,7 @@ public class FoodCartServicesTest {
public void addProducts(){ public void addProducts(){
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer()); OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, 667,new Integer[43], new Customer());
foodCartServices.addProducts(pd); foodCartServices.addProducts(pd);
verify(foodeliveryRepository,times(1)).save(pd); verify(foodeliveryRepository,times(1)).save(pd);
......
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