Commit 13e167d7 authored by snamdeo's avatar snamdeo

commiting the new chaanges with my sql server

parent a7249361
......@@ -2,9 +2,10 @@ plugins {
id 'org.springframework.boot' version '2.7.3'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
id 'jacoco'
}
group = 'com.atimetrik.poc'
group = 'com.poc.altimetrik'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
......@@ -23,11 +24,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
rootProject.name = 'foodelivery'
rootProject.name = 'foodDeliveryApplication'
package com.atimetrik.poc.services;
import com.atimetrik.poc.dto.ProductDetails;
import java.util.List;
public interface FoodCartServices {
public List<ProductDetails> getProducts();
public void addProducts(ProductDetails p);
public void removeProducts(ProductDetails p);
public void updateProduct(ProductDetails p);
}
package com.atimetrik.poc.services;
import com.atimetrik.poc.dto.ProductDetails;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class FoodCartServicesImpl implements FoodCartServices {
List<ProductDetails> product = new ArrayList<>();
public List<ProductDetails> getProducts(){
return product;
}
public void addProducts(ProductDetails p){
product.add(p);
}
public void removeProducts(ProductDetails p){
product.remove(p);
}
public void updateProduct(ProductDetails p){
product.remove(p);
}
}
package com.atimetrik.poc;
package com.poc.altimetrik;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FoodeliveryApplication {
public class FoodDeliveryApplication {
public static void main(String[] args) {
SpringApplication.run(FoodeliveryApplication.class, args);
SpringApplication.run(FoodDeliveryApplication.class, args);
}
}
package com.poc.altimetrik.controller;
import com.poc.altimetrik.dto.ProductDetails;
import com.poc.altimetrik.repository.FetchProductsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/fetchData")
public class FetchProductsController {
@Autowired
FetchProductsRepository fetchProductsRepository;
@GetMapping("/getAllProducts")
@CrossOrigin(origins="http://localhost:3008/")
public ResponseEntity<List<ProductDetails>> getAllProducts(){
List<ProductDetails> products = fetchProductsRepository.findAll();
System.out.println(products);
return ResponseEntity.ok(products);
}
}
package com.atimetrik.poc.controller;
import com.atimetrik.poc.dto.ProductDetails;
import com.atimetrik.poc.services.FoodCartServices;
package com.poc.altimetrik.controller;
import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.services.FoodCartServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -17,29 +16,19 @@ public class FoodCartController {
FoodCartServices shoppingCartServices;
@GetMapping("/getProducts")
public ResponseEntity<List<ProductDetails>> getProducts(){
List<ProductDetails> products = shoppingCartServices.getProducts();
public ResponseEntity<List<OrderDetails>> getProducts(){
List<OrderDetails> products = shoppingCartServices.getProducts();
return ResponseEntity.ok(products);
}
@DeleteMapping("/removeProducts")
public void removeProducts(@RequestBody ProductDetails p){
shoppingCartServices.removeProducts(p);
}
@PostMapping ("/addProducts")
@CrossOrigin(origins="http://localhost:3008/")
public void addProducts(@RequestBody ProductDetails p){
public void addProducts(@RequestBody OrderDetails p){
shoppingCartServices.addProducts(p);
}
@PutMapping("/updateProducts")
public void updateProducts(@RequestBody ProductDetails p){
shoppingCartServices.updateProduct(p);
}
}
package com.poc.altimetrik.controller;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.repository.UserLoggedInRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("api/v1")
public class UserDataController {
@Autowired
UserLoggedInRepository userLoggedInRepository;
@PostMapping("/userLoggedIn")
@CrossOrigin(origins="http://localhost:3008/")
public void addUser(@RequestBody Customer p){
System.out.println(p);
userLoggedInRepository.save(p);
}
}
package com.poc.altimetrik.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Customer {
@Id
@GeneratedValue
private Integer id;
private Integer userId;
private String firstName;
private String lastName;
private String emailId;
@OneToMany(
mappedBy = "customer",
cascade = CascadeType.ALL
)
private List<OrderDetails> orderDetails = new ArrayList<OrderDetails>();
@OneToOne
@JoinColumn(name = "customer_valet_details_id")
private CustomerValetDetails customerValetDetails;
public Customer(Integer userId, String firstName, String lastName, String emailId) {
this.userId = userId;
this.firstName = firstName;
this.lastName = lastName;
this.emailId = emailId;
}
}
package com.atimetrik.poc.dto;
package com.poc.altimetrik.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Customers {
@Table(name = "UserdataDetails")
@Entity
public class CustomerValetDetails {
@Id
@GeneratedValue
private Integer id;
private String email;
private String password;
private Integer valetAmount;
@OneToOne(mappedBy = "customerValetDetails")
private Customer customer;
}
\ No newline at end of file
package com.atimetrik.poc.dto;
package com.poc.altimetrik.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProductDetails {
@Entity
public class OrderDetails {
@Id
@GeneratedValue
private Integer id;
private Integer orderNumber;
private Integer taxPrice;
private Integer shippingPrice;
private Integer totalPrice;
private Integer itemsPrice;
private Integer[] productIds;
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer;
}
package com.poc.altimetrik.dto;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class ProductDetails {
public ProductDetails() {
}
@Id
@GeneratedValue
private Integer id;
public ProductDetails(Integer id, Integer price, String name, String image) {
this.id = id;
this.price = price;
this.name = name;
this.image = image;
}
private Integer price;
private String name;
private String image;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
package com.poc.altimetrik.repository;
import com.poc.altimetrik.dto.ProductDetails;
import org.springframework.data.jpa.repository.JpaRepository;
public interface FetchProductsRepository extends JpaRepository<ProductDetails,Integer> {
}
package com.poc.altimetrik.repository;
import com.poc.altimetrik.dto.OrderDetails;
import org.springframework.data.jpa.repository.JpaRepository;
public interface FoodeliveryRepository extends JpaRepository<OrderDetails,Integer> {
}
package com.poc.altimetrik.repository;
import com.poc.altimetrik.dto.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserLoggedInRepository extends JpaRepository<Customer,Integer> {
}
package com.poc.altimetrik.services;
import com.poc.altimetrik.dto.OrderDetails;
import java.util.List;
public interface FoodCartServices {
public List<OrderDetails> getProducts();
public void addProducts(OrderDetails p);
}
package com.poc.altimetrik.services;
import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.repository.FoodeliveryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class FoodCartServicesImpl implements FoodCartServices {
@Autowired
FoodeliveryRepository foodeliveryRepository;
List<OrderDetails> product = new ArrayList<>();
public List<OrderDetails> getProducts(){
return foodeliveryRepository.findAll();
}
public void addProducts(OrderDetails p){
// System.out.println(c);
foodeliveryRepository.save(p);
}
}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url= jdbc:mysql://localhost:3306/shishirdb
spring.datasource.username=root
spring.datasource.password=Qazwsx@2022#
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
\ No newline at end of file
package com.atimetrik.poc;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FoodeliveryApplicationTests {
@Test
void contextLoads() {
}
}
package com.poc.altimetrik.controller;
import com.poc.altimetrik.controller.FetchProductsController;
import com.poc.altimetrik.dto.ProductDetails;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
@SpringBootTest
public class FetchProductControllerTest {
@MockBean private JdbcTemplate jdbcTemplate;
@Autowired private FetchProductsController fetchProductsController;
@Test
public void getAllTheProducts() throws SQLException, IOException {
String sql = "Select * from ProductDetails";
ProductDetails pd = new ProductDetails();
pd.setId(1);pd.setName("Pizza"); pd.setPrice(300);pd.setImage("./Images/Pizza2.png");
List<ProductDetails> lpd = new ArrayList<ProductDetails>();
when(jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(ProductDetails.class))).thenReturn(lpd);
assertEquals("200 OK",fetchProductsController.getAllProducts().getStatusCode().toString());
}
}
package com.poc.altimetrik.controller;
import com.poc.altimetrik.controller.FoodCartController;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.services.FoodCartServices;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
@SpringBootTest
class FoodCartControllerTest {
@MockBean
private FoodCartServices foodCartServices;
@Autowired
private FoodCartController foodCartController;
@Test
public void getProducts(){
when(foodCartServices.getProducts()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals("200 OK",foodCartController.getProducts().getStatusCode().toString());
}
@Test
public void addProducts(){
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer());
foodCartController.addProducts(pd);
verify(foodCartServices,times(1)).addProducts(pd);
}
}
package com.poc.altimetrik.controller;
import com.poc.altimetrik.controller.UserDataController;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.repository.UserLoggedInRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@SpringBootTest
public class UserDataControllerTest {
@MockBean
UserLoggedInRepository userLoggedInRepository;
@Autowired
UserDataController userDataController;
@Test
public void removeProducts(){
Customer c = new Customer(233, "Shishir", "Namdeo","shishirnamdeo220@gmaik.com");
userDataController.addUser(c);
verify(userLoggedInRepository,times(1)).save(c);
}
}
package com.poc.altimetrik.services;
import com.poc.altimetrik.dto.Customer;
import com.poc.altimetrik.dto.OrderDetails;
import com.poc.altimetrik.dto.ProductDetails;
import com.poc.altimetrik.repository.FoodeliveryRepository;
import com.poc.altimetrik.services.FoodCartServices;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
@SpringBootTest
public class FoodCartServicesTest {
@MockBean
FoodeliveryRepository foodeliveryRepository;
@Autowired
FoodCartServices foodCartServices;
@MockBean
List<ProductDetails> lpd;
@Test
public void getProducts(){
when(foodeliveryRepository.findAll()).thenReturn(Stream.of(
new OrderDetails(300,3761,0,0,42,342,new Integer[2],new Customer())).collect(Collectors.toList()));
assertEquals(1,foodCartServices.getProducts().size());
}
@Test
public void addProducts(){
OrderDetails pd = new OrderDetails(300,3721,4356,6456,6565,454, new Integer[43], new Customer());
foodCartServices.addProducts(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