Browse Source

Remove duplicated directory

Nitya
Nitya Jain 4 years ago
parent
commit
966a9bfe00
970 changed files with 0 additions and 43585 deletions
  1. 0
      springboot_backend/.metadata/.lock
  2. 10184
      springboot_backend/.metadata/.log
  3. 54
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/10/a0cd36544d1c001c1175ef5c8fe3bc4a
  4. 26
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/11/e0fa51ab2820001c1fd4fcbaef3ed6f3
  5. 54
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/12/600672374a1c001c1175ef5c8fe3bc4a
  6. 70
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/14/b065d7fb7620001c1639f432a894b632
  7. 3
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/14/d09c1a101e20001c1fd4fcbaef3ed6f3
  8. 25
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/17/d01cbf402820001c1fd4fcbaef3ed6f3
  9. 29
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/17/f0c722ff6a22001c17d1e4ac7a211a08
  10. 65
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/18/10f54a99841c001c1e2b8f537ef912f3
  11. 79
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/19/301d00902820001c1fd4fcbaef3ed6f3
  12. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/20fa1d4a6f20001c18d2b7903485cc51
  13. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/30e882aca31c001c1afc8a1edde7498c
  14. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50786ec7e820001c1ad9f76e81c64a6c
  15. 26
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1d/1071dd372920001c1fd4fcbaef3ed6f3
  16. 10
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10f615602a20001c1fd4fcbaef3ed6f3
  17. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1f/d087e071ba1b001c1da2ffc18848673d
  18. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2/d09e07ff6a22001c17d1e4ac7a211a08
  19. 6
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/21/b0b4e9d31a20001c1fd4fcbaef3ed6f3
  20. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/23/2082116b1e20001c1fd4fcbaef3ed6f3
  21. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/23/20bce371ba1b001c1da2ffc18848673d
  22. 2
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/106aded31a20001c1fd4fcbaef3ed6f3
  23. 32
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/80bfb9287f20001c1639f432a894b632
  24. 27
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/c0a038e22a20001c1fd4fcbaef3ed6f3
  25. 62
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/25/a03a65f62920001c1fd4fcbaef3ed6f3
  26. 109
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/25/e06514b39622001c17d1e4ac7a211a08
  27. 3
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/27/f08ce0d31a20001c1fd4fcbaef3ed6f3
  28. 43
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/28/b0d5fba9831c001c1e2b8f537ef912f3
  29. 33
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2a/308d91291421001c12d2a58e3b8f44a0
  30. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2c/708547971d20001c1fd4fcbaef3ed6f3
  31. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2d/90366dcb1f20001c1fd4fcbaef3ed6f3
  32. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2f/00fb58532220001c1fd4fcbaef3ed6f3
  33. 41
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/30/90521f2fab1c001c1ceba011ddc7f939
  34. 21
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/30fa0aff6a22001c17d1e4ac7a211a08
  35. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/40185c4bb51b001c1da2ffc18848673d
  36. 2
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/703dced31a20001c1fd4fcbaef3ed6f3
  37. 62
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0a2027e2a20001c1fd4fcbaef3ed6f3
  38. 15
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0f6e773861c001c1e2b8f537ef912f3
  39. 68
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/33/30a6a1602820001c1fd4fcbaef3ed6f3
  40. 18
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/33/c0b804261b21001c12d2a58e3b8f44a0
  41. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/37/9026e7d11d20001c1fd4fcbaef3ed6f3
  42. 111
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/38/70b8bb272720001c1fd4fcbaef3ed6f3
  43. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/38/e0cdb923b61b001c1da2ffc18848673d
  44. 28
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/39/c02bc39a2a20001c1fd4fcbaef3ed6f3
  45. 54
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/4028d9654e1c001c1175ef5c8fe3bc4a
  46. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/6063503f7f1c001c1e2b8f537ef912f3
  47. 105
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/70be07a12920001c1fd4fcbaef3ed6f3
  48. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/a041d05d7320001c1639f432a894b632
  49. 91
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3b/40aa9a292a20001c1fd4fcbaef3ed6f3
  50. 3
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3b/8046d3d31a20001c1fd4fcbaef3ed6f3
  51. 18
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3c/0087222e1421001c12d2a58e3b8f44a0
  52. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3c/f00f35e02720001c1fd4fcbaef3ed6f3
  53. 43
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3f/208f99af841c001c1e2b8f537ef912f3
  54. 37
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3f/c06ef6901221001c12d2a58e3b8f44a0
  55. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/40/a0dd5cf31e20001c1fd4fcbaef3ed6f3
  56. 43
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/00f0b258861c001c1e2b8f537ef912f3
  57. 19
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/a04eed1c481c001c1175ef5c8fe3bc4a
  58. 0
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/f0ad9e8b1f20001c1fd4fcbaef3ed6f3
  59. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/42/001f86c7e820001c1ad9f76e81c64a6c
  60. 70
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/42/b07930b67720001c1639f432a894b632
  61. 75
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/44/00842108481c001c1175ef5c8fe3bc4a
  62. 4
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/44/70bfdb841021001c12d2a58e3b8f44a0
  63. 100
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/45/604c0e592920001c1fd4fcbaef3ed6f3
  64. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/45/f0e96108ac1c001c1ceba011ddc7f939
  65. 15
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/47/e077bf5d851c001c1e2b8f537ef912f3
  66. 155
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/48/a0bd064d2c20001c1fd4fcbaef3ed6f3
  67. 25
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/48/f0c6588c811c001c1e2b8f537ef912f3
  68. 69
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/4d/800c8463811c001c1e2b8f537ef912f3
  69. 27
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/4f/701e18e92a20001c1fd4fcbaef3ed6f3
  70. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/50/f0f3b6ed7720001c1639f432a894b632
  71. 7
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/52/d0c0ed841021001c12d2a58e3b8f44a0
  72. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/53/a08945971d20001c1fd4fcbaef3ed6f3
  73. 25
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/55/d0287e097f1c001c1e2b8f537ef912f3
  74. 3
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/0072e4841021001c12d2a58e3b8f44a0
  75. 65
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/200956c2811c001c1e2b8f537ef912f3
  76. 32
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/a05d59007220001c1639f432a894b632
  77. 2
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/d07e1f101e20001c1fd4fcbaef3ed6f3
  78. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/58/4095b7f2a21c001c1afc8a1edde7498c
  79. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/59/704ab3ed7720001c1639f432a894b632
  80. 8
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0d1214d2a20001c1fd4fcbaef3ed6f3
  81. 32
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5d/c03add7fe420001c1ad9f76e81c64a6c
  82. 23
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5e/c07c6cc9ba1b001c1da2ffc18848673d
  83. 8
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5e/e00befd31a20001c1fd4fcbaef3ed6f3
  84. 90
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/00ce31622620001c1fd4fcbaef3ed6f3
  85. 3
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/b0a121101e20001c1fd4fcbaef3ed6f3
  86. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/b0fc4cada81c001c15eabe5cf52659ba
  87. 8
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c00af0841021001c12d2a58e3b8f44a0
  88. 65
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6/b06d5c0f801c001c1e2b8f537ef912f3
  89. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/60/809f5596a81c001c15eabe5cf52659ba
  90. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/61/d0dafdfe6a22001c17d1e4ac7a211a08
  91. 69
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/63/50d1ae58861c001c1e2b8f537ef912f3
  92. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/65/5076df81a51c001c18e2b55ca6c81bda
  93. 54
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/65/70a90d754a1c001c1175ef5c8fe3bc4a
  94. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/66/c0a652ed1d20001c1fd4fcbaef3ed6f3
  95. 5
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/68/50d2b89c7c22001c17d1e4ac7a211a08
  96. 13
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/68/e0ee4a8daf1a001c19bcf3b7e4125f31
  97. 74
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6a/20a559847620001c1639f432a894b632
  98. 4
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6c/600fe4d31a20001c1fd4fcbaef3ed6f3
  99. 65
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6d/2094d5f92720001c1fd4fcbaef3ed6f3
  100. 100
      springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/7/e084e6cd2820001c1fd4fcbaef3ed6f3

0
springboot_backend/.metadata/.lock

10184
springboot_backend/.metadata/.log
File diff suppressed because it is too large
View File

54
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/10/a0cd36544d1c001c1175ef5c8fe3bc4a

@ -1,54 +0,0 @@
package com.example.demo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = UserServiceApplication.class)
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserControllerTest {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void shouldFindMemberById() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/user/" + "2")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").value(2))
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.name").value("Mary Brown"))
.andExpect(jsonPath("$.email").value("mary.b@gmail.com"))
.andExpect(jsonPath("$.*", hasSize(3)))
.andReturn();
}
}

26
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/11/e0fa51ab2820001c1fd4fcbaef3ed6f3

@ -1,26 +0,0 @@
package com.example.demo;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface CartRepo extends JpaRepository<Cart, Long> {
List<Cart> findByUserId(Long uid);
@Query("select c from Cart c join c.user u where u.id = ?1")
List<Cart> getItems(Long uid);
@Modifying
@Transactional
@Query("delete from Cart c where c.user.id=?1")
void deleteItems(Long uid);
}

54
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/12/600672374a1c001c1175ef5c8fe3bc4a

@ -1,54 +0,0 @@
package com.example.demo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.sundaydevblog.springrestapitest.controller.MemberController;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = UserServiceApplication.class)
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserControllerTest {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void shouldFindMemberById() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/userapi/user" + "2")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").value(2))
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.name").value("Mary Brown"))
.andExpect(jsonPath("$.email").value("mary.b@gmail.com"))
.andExpect(jsonPath("$.*", hasSize(3)))
.andReturn();
}
}

70
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/14/b065d7fb7620001c1639f432a894b632

@ -1,70 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.config.MessagingConfig;
import com.example.demo.model.Cart;
import com.example.demo.model.OrderStatus;
import com.example.demo.model.Orders;
import com.example.demo.repository.CartRepo;
import com.example.demo.repository.OrderRepo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class OrderController {
@Autowired
private OrderRepo orderRepository;
@Autowired
private CartRepo cartRepository;
@Autowired
private RabbitTemplate template;
@PostMapping("/addOrder/{uid}")
public void add(@PathVariable Long uid) {
List<Cart> cart = cartRepository.getItems(uid);
Orders ord = new Orders();
for(Cart c : cart) {
ord.setQuantity(c.getQuantity());
ord.setTotalPrice(c.getTotalPrice());
ord.setUid(c.getUser().getId());
ord.setUsername(c.getUser().getUsername());
ord.setPid(c.getProduct().getId());
ord.setPname(c.getProduct().getName());
orderRepository.save(ord);
OrderStatus orderStatus = new OrderStatus(ord, "PROCESS", "order placed succesfully in " + uid);
template.convertAndSend(MessagingConfig.EXCHANGE, MessagingConfig.ROUTING_KEY, orderStatus);
}
cartRepository.deleteItems(uid);
}
@DeleteMapping("/orders/{oid}")
public void deleteFromOrder(@PathVariable("oid") Long oid) {
orderRepository.deleteById(oid);
}
}

3
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/14/d09c1a101e20001c1fd4fcbaef3ed6f3

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

25
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/17/d01cbf402820001c1fd4fcbaef3ed6f3

@ -1,25 +0,0 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import com.myrestapp.demo.model.User;
import com.myrestapp.demo.repository.UserRepo;
@Service
public class MyUserDetailsService implements UserDetailsService
{
@Autowired
private UserRepo userRepository;
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException
{
User user=userRepository.getByUsername(username);
return user;
}
}

29
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/17/f0c722ff6a22001c17d1e4ac7a211a08

@ -1,29 +0,0 @@
package com.javatechie.rabbitmq.demo.consumer;
import com.javatechie.rabbitmq.demo.config.MessagingConfig;
import com.javatechie.rabbitmq.demo.dto.OrderStatus;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
@Component
public class User {
@RabbitListener(queues = MessagingConfig.QUEUE)
public void consumeMessageFromQueue(OrderStatus orderStatus) {
System.out.println(orderStatus);
MongoClient client = new MongoClient("labs4.koteshwar.com", 27017);
MongoDatabase db = client.getDatabase("paris");
MongoCollection<Document> table = db.getCollection("expressGrocery");
Document doc = new Document();
doc.append("Order status:", orderStatus);
table.insertOne(doc);
client.close();
}
}

65
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/18/10f54a99841c001c1e2b8f537ef912f3

@ -1,65 +0,0 @@
package com.example.demo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
public class UserServiceTest {
@Mock
private UserRepo userRepository;
@InjectMocks
private UserServiceImpl userService;
private User m1 = new User("Paddy Welbourn", "pwelbourn0@ed.gov");
private User m2 = new User("Wren Flori", "wflori2@webeden.co.uk");
private User m3 = new User("Ambrosio Smewing", "asmewing4@hostgator.com");
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
m1.setId(1L);
m2.setId(2L);
m3.setId(3L);
}
@Test
public void testGetUserById() {
//given
given(userRepository.findById(1L)).willReturn(Optional.of(m1));
//calling method under the test
User result = userService.getUserById(1L);
//assert
// assertThat(result.isPresent()).isTrue();
//assert
// assertUserFields(result.orElseGet(null));
//verify that repository was called
verify(userRepository, times(1)).findById(1L);
}
private void assertUserFields(User user) {
assertThat(user.getId()).isInstanceOf(Long.class);
assertThat(user.getId()).isEqualTo(1);
assertThat(user.getUsername()).isEqualTo("Paddy Welbourn");
assertThat(user.getEmail()).isEqualTo("pwelbourn0@ed.gov");
}
}

79
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/19/301d00902820001c1fd4fcbaef3ed6f3

@ -1,79 +0,0 @@
package com.example.demo;
public class CartDto {
private Long cid;
private double quantity;
private double totalPrice;
private Long pid;
private String imag;
private String name;
private double price;
private Long uid;
private String username;
private String apartments;
public Long getCid() {
return cid;
}
public void setCid(Long cid) {
this.cid = cid;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public Double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(Double totalPrice) {
this.totalPrice = totalPrice;
}
public Long getPid() {
return pid;
}
public void setPid(Long pid) {
this.pid = pid;
}
public String getImag() {
return imag;
}
public void setImag(String imag) {
this.imag = imag;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getApartments() {
return apartments;
}
public void setApartments(String apartments) {
this.apartments = apartments;
}
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/20fa1d4a6f20001c18d2b7903485cc51

@ -1,5 +0,0 @@
server.port=59277
spring.security.user.name=user
spring.security.user.password=24gh39ugh0

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/30e882aca31c001c1afc8a1edde7498c

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\java\\com\\example");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50786ec7e820001c1ad9f76e81c64a6c

@ -1,13 +0,0 @@
server.port=5008
spring.datasource.url=jdbc:mysql://10.3.117.26:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/productapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

26
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1d/1071dd372920001c1fd4fcbaef3ed6f3

@ -1,26 +0,0 @@
package com.example.demo.repository;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface CartRepo extends JpaRepository<Cart, Long> {
List<Cart> findByUserId(Long uid);
@Query("select c from Cart c join c.user u where u.id = ?1")
List<Cart> getItems(Long uid);
@Modifying
@Transactional
@Query("delete from Cart c where c.user.id=?1")
void deleteItems(Long uid);
}

10
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10f615602a20001c1fd4fcbaef3ed6f3

@ -1,10 +0,0 @@
package com.example.demo;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.demo.model.Orders;
public interface OrderRepo extends JpaRepository<Orders, Long> {
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/1f/d087e071ba1b001c1da2ffc18848673d

@ -1,5 +0,0 @@
package com.example.demo;
public class UserServiceImpl {
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2/d09e07ff6a22001c17d1e4ac7a211a08

@ -1,13 +0,0 @@
server.port=5008
spring.datasource.url=jdbc:mysql://10.3.117.23:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/productapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

6
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/21/b0b4e9d31a20001c1fd4fcbaef3ed6f3

@ -1,6 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/23/2082116b1e20001c1fd4fcbaef3ed6f3

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/23/20bce371ba1b001c1da2ffc18848673d

@ -1,5 +0,0 @@
package com.example.demo;
public interface UserService {
}

2
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/106aded31a20001c1fd4fcbaef3ed6f3

@ -1,2 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

32
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/80bfb9287f20001c1639f432a894b632

@ -1,32 +0,0 @@
package hello
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
class LoadTest extends Simulation {
val httpProtocol: HttpProtocolBuilder = http
.baseUrl("http://localhost:5007")
object HelloWorldResource {
val get: ChainBuilder = exec(http("Logging on")
.get("/login")
.basicAuth("user", "24gh39ugh0"))
}
val myScenario: ScenarioBuilder = scenario("RampUpUsers")
.exec(HelloWorldResource.get)
setUp(myScenario.inject(
incrementUsersPerSec(20)
.times(5)
.eachLevelLasting(5 seconds)
.separatedByRampsLasting(5 seconds)
.startingFrom(20)
)).protocols(httpProtocol)
.assertions(global.successfulRequests.percent.is(100))
}

27
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/24/c0a038e22a20001c1fd4fcbaef3ed6f3

@ -1,27 +0,0 @@
package com.example.demo.repository;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface CartRepo extends JpaRepository<Cart, Long> {
List<Cart> findByUserId(Long uid);
@Query("select c from Cart c join c.user u where u.id = ?1")
List<Cart> getItems(Long uid);
@Modifying
@Transactional
@Query("delete from Cart c where c.user.id=?1")
void deleteItems(Long uid);
}

62
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/25/a03a65f62920001c1fd4fcbaef3ed6f3

@ -1,62 +0,0 @@
package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class OrderController {
@Autowired
private OrderRepo orderRepository;
@Autowired
private CartRepo cartRepository;
@Autowired
private RabbitTemplate template;
@PostMapping("/addOrder/{uid}")
public void add(@PathVariable Long uid) {
List<Cart> cart = cartRepository.getItems(uid);
Orders ord = new Orders();
for(Cart c : cart) {
ord.setQuantity(c.getQuantity());
ord.setTotalPrice(c.getTotalPrice());
ord.setUid(c.getUser().getId());
ord.setUsername(c.getUser().getUsername());
ord.setPid(c.getProduct().getId());
ord.setPname(c.getProduct().getName());
orderRepository.save(ord);
OrderStatus orderStatus = new OrderStatus(ord, "PROCESS", "order placed succesfully in " + uid);
template.convertAndSend(MessagingConfig.EXCHANGE, MessagingConfig.ROUTING_KEY, orderStatus);
}
cartRepository.deleteItems(uid);
}
@DeleteMapping("/orders/{oid}")
public void deleteFromOrder(@PathVariable("oid") Long oid) {
orderRepository.deleteById(oid);
}
}

109
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/25/e06514b39622001c17d1e4ac7a211a08

@ -1,109 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.model.Cart;
import com.example.demo.model.CartDto;
import com.example.demo.model.Product;
import com.example.demo.model.User;
import com.example.demo.repository.CartRepo;
import com.example.demo.repository.ProductRepo;
import com.example.demo.repository.UserRepo;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class CartController {
@Autowired
private UserRepo userRepository;
@Autowired
private ProductRepo productRepository;
@Autowired
private CartRepo cartRepository;
@PostMapping("/cart/{uid}/{pid}")
public Cart postCart(@RequestBody Cart cart, @PathVariable("uid") Long uid, @PathVariable("pid") Long pid) {
Product product = productRepository.getById(pid);
User user = userRepository.getById(uid);
cart.setUser(user);
cart.setProduct(product);
int q=1;
cart.setQuantity(q);
cart.setTotalPrice(cart.getProduct().getPrice()*cart.getQuantity());
return cartRepository.save(cart);
}
@GetMapping("/cartdto/{uid}")
public List<CartDto> getCartdto(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
List<CartDto> listDto = new ArrayList<>();
list = cartRepository.findByUserId(uid);
for(Cart c : list) {
CartDto cartDto = new CartDto();
cartDto.setCid(c.getId());
cartDto.setQuantity(c.getQuantity());
cartDto.setTotalPrice(c.getQuantity()*c.getProduct().getPrice());
cartDto.setPid(c.getProduct().getId());
cartDto.setImag(c.getProduct().getImag());
cartDto.setName(c.getProduct().getName());
cartDto.setPrice(c.getProduct().getPrice());
cartDto.setUid(c.getUser().getId());
cartDto.setUsername(c.getUser().getUsername());
cartDto.setApartments(c.getUser().getApartments());
listDto.add(cartDto);
}
return listDto;
}
@GetMapping("/cart/{uid}")
public List<Cart> getCartByUser(@PathVariable("uid") Long uid) {
return cartRepository.findByUserId(uid);
}
@PostMapping("/cartquant/{cid}/{quantity}")
public Double addQuantity(@PathVariable("cid") Long cid, @PathVariable("quantity") Double quantity) {
Cart cart= cartRepository.getById(cid);
cart.setQuantity(quantity);
cart.setTotalPrice(quantity*cart.getProduct().getPrice());
cartRepository.save(cart);
return cart.getTotalPrice();
}
@PostMapping("/cartsum/{uid}")
public Double getCartSum(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
list = cartRepository.findByUserId(uid);
Cart cart = new Cart();
Double sum = 0.0;
for(Cart c : list) {
sum=sum+ c.getTotalPrice();
}
return sum;
}
@DeleteMapping("/cart/{cid}")
public void deleteFromCart(@PathVariable("cid") Long cid) {
cartRepository.deleteById(cid);
}
}

3
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/27/f08ce0d31a20001c1fd4fcbaef3ed6f3

@ -1,3 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

43
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/28/b0d5fba9831c001c1e2b8f537ef912f3

@ -1,43 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
@Override
public User saveUser(User user) {
// TODO Auto-generated method stub
return userRepository.save(user);
}
@Override
public List<User> findAllAccounts() {
// TODO Auto-generated method stub
return userRepository.findAll();
}
@Override
public User getUserById(Long id) {
// TODO Auto-generated method stub
return userRepository.findById(id);
}
}

33
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2a/308d91291421001c12d2a58e3b8f44a0

@ -1,33 +0,0 @@
package com.javatechie.rabbitmq.demo.consumer;
import com.javatechie.rabbitmq.demo.config.MessagingConfig;
import com.javatechie.rabbitmq.demo.dto.OrderStatus;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
@Component
public class User {
@RabbitListener(queues = MessagingConfig.QUEUE)
public void consumeMessageFromQueue(OrderStatus orderStatus) {
System.out.println(orderStatus);
MongoClient client = new MongoClient("localhost", 27017);
MongoDatabase db = client.getDatabase("practice");
MongoCollection<Document> table = db.getCollection("employ");
Document doc = new Document();
doc.append("empno", 10);
doc.append("name", "Sai Kumar");
doc.append("dept", "Java");
doc.append("desig", "Programmer");
doc.append("basic", 98892);
table.insertOne(doc);
client.close();
}
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2c/708547971d20001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo;
public class Cart {
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2d/90366dcb1f20001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo;
public class MessagingConfig {
}

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/2f/00fb58532220001c1fd4fcbaef3ed6f3

41
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/30/90521f2fab1c001c1ceba011ddc7f939

@ -1,41 +0,0 @@
package com.example.demo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
@RestController
public class ProductController {
@Autowired
private ProductRepo productRepository;
@GetMapping("/product")
public List<Product> getAllProducts(){
List<Product> list = productRepository.findAll();
return list;
}
@PostMapping("/product")
public List<Product> postProduct(@RequestBody Product product) {
List<Product> list = productRepository.save(product);
return list;
}
@GetMapping("/product/{category}")
public List<Product> getAllProductsByCategory(@PathVariable("category") String category) {
return productRepository.findByCategory(category);
}
}

21
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/30fa0aff6a22001c17d1e4ac7a211a08

@ -1,21 +0,0 @@
server.port=5009
spring.datasource.url=jdbc:mysql://10.3.117.23:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/orderapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
spring.rabbitmq.host=labs4.koteshwar.com
spring.rabbitmq.password=guest
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/40185c4bb51b001c1da2ffc18848673d

2
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/703dced31a20001c1fd4fcbaef3ed6f3

@ -1,2 +0,0 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

62
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0a2027e2a20001c1fd4fcbaef3ed6f3

@ -1,62 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class OrderController {
@Autowired
private OrderRepo orderRepository;
@Autowired
private CartRepo cartRepository;
@Autowired
private RabbitTemplate template;
@PostMapping("/addOrder/{uid}")
public void add(@PathVariable Long uid) {
List<Cart> cart = cartRepository.getItems(uid);
Orders ord = new Orders();
for(Cart c : cart) {
ord.setQuantity(c.getQuantity());
ord.setTotalPrice(c.getTotalPrice());
ord.setUid(c.getUser().getId());
ord.setUsername(c.getUser().getUsername());
ord.setPid(c.getProduct().getId());
ord.setPname(c.getProduct().getName());
orderRepository.save(ord);
OrderStatus orderStatus = new OrderStatus(ord, "PROCESS", "order placed succesfully in " + uid);
template.convertAndSend(MessagingConfig.EXCHANGE, MessagingConfig.ROUTING_KEY, orderStatus);
}
cartRepository.deleteItems(uid);
}
@DeleteMapping("/orders/{oid}")
public void deleteFromOrder(@PathVariable("oid") Long oid) {
orderRepository.deleteById(oid);
}
}

15
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0f6e773861c001c1e2b8f537ef912f3

@ -1,15 +0,0 @@
package com.example.demo;
import java.util.List;
public interface UserService {
User saveUser(User user);
List<User> findAllAccounts();
Optional<User> getUserById(Long id);
}

68
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/33/30a6a1602820001c1fd4fcbaef3ed6f3

@ -1,68 +0,0 @@
package com.example.demo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class Cart {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private double quantity;
private double totalPrice;
@OneToOne
private Product product;
@OneToOne
private User user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
}

18
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/33/c0b804261b21001c12d2a58e3b8f44a0

@ -1,18 +0,0 @@
server.port=58277
spring.rabbitmq.host=labs4.koteshwar.com
spring.rabbitmq.password=guest
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.application.name=Mongo DB Example
#Mongo Config
spring.data.mongodb.host=labs4.koteshwar.com
spring.data.mongodb.port=27017
spring.data.mongodb.database=paris
spring.data.mongodb.repositories.enabled=true
spring.mongodb.username=parisadmin
spring.mongodb.password=password

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/37/9026e7d11d20001c1fd4fcbaef3ed6f3

111
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/38/70b8bb272720001c1fd4fcbaef3ed6f3

@ -1,111 +0,0 @@
package com.example.demo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String fullname;
private String password;
private String gender;
private Long phone;
private String email;
private String address;
private String city;
private String state;
private int pincode;
private String apartments;
public User() {
super();
// TODO Auto-generated constructor stub
}
public User(String username, String email) {
super();
this.username = username;
this.email = email;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Long getPhone() {
return phone;
}
public void setPhone(Long phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getPincode() {
return pincode;
}
public void setPincode(int pincode) {
this.pincode = pincode;
}
public String getApartments() {
return apartments;
}
public void setApartments(String apartments) {
this.apartments = apartments;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/38/e0cdb923b61b001c1da2ffc18848673d

28
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/39/c02bc39a2a20001c1fd4fcbaef3ed6f3

@ -1,28 +0,0 @@
package com.example.demo.repository;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import com.example.demo.model.Cart;
public interface CartRepo extends JpaRepository<Cart, Long> {
List<Cart> findByUserId(Long uid);
@Query("select c from Cart c join c.user u where u.id = ?1")
List<Cart> getItems(Long uid);
@Modifying
@Transactional
@Query("delete from Cart c where c.user.id=?1")
void deleteItems(Long uid);
}

54
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/4028d9654e1c001c1175ef5c8fe3bc4a

@ -1,54 +0,0 @@
package com.example.demo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = UserServiceApplication.class)
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserControllerTest {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void shouldFindMemberById() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/user/" + "1")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").value(2))
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.name").value("Mary Brown"))
.andExpect(jsonPath("$.email").value("mary.b@gmail.com"))
.andExpect(jsonPath("$.*", hasSize(3)))
.andReturn();
}
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/6063503f7f1c001c1e2b8f537ef912f3

@ -1,13 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
public interface UserService {
Optional<User> getUserById(long id);
User saveUser(User user);
List<User> findAllAccounts();
}

105
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/70be07a12920001c1fd4fcbaef3ed6f3

@ -1,105 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.dto.CartDto;
import com.example.demo.model.Cart;
import com.example.demo.repository.CartRepo;
import com.example.demo.repository.UserRepo;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class CartController {
@Autowired
private UserRepo userRepository;
@Autowired
private ProductRepo productRepository;
@Autowired
private CartRepo cartRepository;
@PostMapping("/cart/{uid}/{pid}")
public Cart postCart(@RequestBody Cart cart, @PathVariable("uid") Long uid, @PathVariable("pid") Long pid) {
Product product = productRepository.getById(pid);
User user = userRepository.getById(uid);
cart.setUser(user);
cart.setProduct(product);
int q=1;
cart.setQuantity(q);
cart.setTotalPrice(cart.getProduct().getPrice()*cart.getQuantity());
return cartRepository.save(cart);
}
@GetMapping("/cartdto/{uid}")
public List<CartDto> getCartdto(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
List<CartDto> listDto = new ArrayList<>();
list = cartRepository.findByUserId(uid);
for(Cart c : list) {
CartDto cartDto = new CartDto();
cartDto.setCid(c.getId());
cartDto.setQuantity(c.getQuantity());
cartDto.setTotalPrice(c.getQuantity()*c.getProduct().getPrice());
cartDto.setPid(c.getProduct().getId());
cartDto.setImag(c.getProduct().getImag());
cartDto.setName(c.getProduct().getName());
cartDto.setPrice(c.getProduct().getPrice());
cartDto.setUid(c.getUser().getId());
cartDto.setUsername(c.getUser().getUsername());
cartDto.setApartments(c.getUser().getApartments());
listDto.add(cartDto);
}
return listDto;
}
@GetMapping("/cart/{uid}")
public List<Cart> getCartByUser(@PathVariable("uid") Long uid) {
return cartRepository.findByUserId(uid);
}
@PostMapping("/cartquant/{cid}/{quantity}")
public Double addQuantity(@PathVariable("cid") Long cid, @PathVariable("quantity") Double quantity) {
Cart cart= cartRepository.getById(cid);
cart.setQuantity(quantity);
cart.setTotalPrice(quantity*cart.getProduct().getPrice());
cartRepository.save(cart);
return cart.getTotalPrice();
}
@PostMapping("/cartsum/{uid}")
public Double getCartSum(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
list = cartRepository.findByUserId(uid);
Cart cart = new Cart();
Double sum = 0.0;
for(Cart c : list) {
sum=sum+ c.getTotalPrice();
}
return sum;
}
@DeleteMapping("/cart/{cid}")
public void deleteFromCart(@PathVariable("cid") Long cid) {
cartRepository.deleteById(cid);
}
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3a/a041d05d7320001c1639f432a894b632

@ -1,13 +0,0 @@
server.port=5008
spring.datasource.url=jdbc:mysql://localhost:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=Password123
server.servlet.context-path=/productapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

91
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3b/40aa9a292a20001c1fd4fcbaef3ed6f3

@ -1,91 +0,0 @@
package com.example.demo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class Orders {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private double quantity;
private double totalPrice;
private Long uid;
private String username;
private Long pid;
private String pname;
public Orders() {
super();
// TODO Auto-generated constructor stub
}
public Orders(Long id, double quantity, double totalPrice, Long uid, String username, Long pid, String pname) {
super();
this.id = id;
this.quantity = quantity;
this.totalPrice = totalPrice;
this.uid = uid;
this.username = username;
this.pid = pid;
this.pname = pname;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Long getPid() {
return pid;
}
public void setPid(Long pid) {
this.pid = pid;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
@Override
public String toString() {
return "Orders [id=" + id + ", quantity=" + quantity + ", totalPrice=" + totalPrice + ", uid=" + uid
+ ", username=" + username + ", pid=" + pid + ", pname=" + pname + "]";
}
}

3
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3b/8046d3d31a20001c1fd4fcbaef3ed6f3

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

18
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3c/0087222e1421001c12d2a58e3b8f44a0

@ -1,18 +0,0 @@
server.port=58277
spring.rabbitmq.host=labs4.koteshwar.com
spring.rabbitmq.password=guest
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.application.name=Mongo DB Example
#Mongo Config
spring.data.mongodb.host=labs4.koteshwar.com
spring.data.mongodb.port=27017
spring.data.mongodb.database=mongo
spring.data.mongodb.repositories.enabled=true
spring.mongodb.username=parisadmin
spring.mongodb.password=password

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3c/f00f35e02720001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo.securityfile;
public class MyUsersDetailsService {
}

43
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3f/208f99af841c001c1e2b8f537ef912f3

@ -1,43 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
@Override
public User saveUser(User user) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<User> findAllAccounts() {
// TODO Auto-generated method stub
return null;
}
@Override
public User getUserById(Long id) {
// TODO Auto-generated method stub
return null;
}
}

37
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/3f/c06ef6901221001c12d2a58e3b8f44a0

@ -1,37 +0,0 @@
package com.javatechie.rabbitmq.demo.consumer;
import com.javatechie.rabbitmq.demo.config.MessagingConfig;
import com.javatechie.rabbitmq.demo.dto.OrderStatus;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
@Component
public class User {
@RabbitListener(queues = MessagingConfig.QUEUE)
public void consumeMessageFromQueue(OrderStatus orderStatus) {
System.out.println(orderStatus);
public class AddEmploy {
public static void main(String[] args) {
MongoClient client = new MongoClient("localhost", 27017);
MongoDatabase db = client.getDatabase("practice");
MongoCollection<Document> table = db.getCollection("employ");
Document doc = new Document();
doc.append("empno", 10);
doc.append("name", "Sai Kumar");
doc.append("dept", "Java");
doc.append("desig", "Programmer");
doc.append("basic", 98892);
table.insertOne(doc);
client.close();
}
}
}
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/40/a0dd5cf31e20001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo;
public interface OrderRepo {
}

43
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/00f0b258861c001c1e2b8f537ef912f3

@ -1,43 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
@Override
public User saveUser(User user) {
// TODO Auto-generated method stub
return userRepository.save(user);
}
@Override
public List<User> findAllAccounts() {
// TODO Auto-generated method stub
return userRepository.findAll();
}
@Override
public User getUserById(Long id) {
// TODO Auto-generated method stub
return userRepository.findById(id);
}
}

19
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/a04eed1c481c001c1175ef5c8fe3bc4a

@ -1,19 +0,0 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
class UserServiceApplicationTests {
@Test
void contextLoads() {
}
}

0
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/41/f0ad9e8b1f20001c1fd4fcbaef3ed6f3

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/42/001f86c7e820001c1ad9f76e81c64a6c

@ -1,13 +0,0 @@
server.port=5006
spring.datasource.url=jdbc:mysql://10.3.117.26:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/cartapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

70
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/42/b07930b67720001c1639f432a894b632

@ -1,70 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.config.MessagingConfig;
import com.example.demo.model.Cart;
import com.example.demo.model.OrderStatus;
import com.example.demo.model.Orders;
import com.example.demo.repository.CartRepo;
import com.example.demo.repository.OrderRepo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class OrderController {
@Autowired
private OrderRepo orderRepository;
@Autowired
private CartRepo cartRepository;
@Autowired
private RabbitTemplate template;
@PostMapping("/addOrder/{uid}")
public void add(@PathVariable Long uid) {
List<Cart> cart = cartRepository.getItems(uid);
Orders ord = new Orders();
for(Cart c : cart) {
ord.setQuantity(c.getQuantity());
ord.setTotalPrice(c.getTotalPrice());
ord.setUid(c.getUser().getId());
ord.setUsername(c.getUser().getUsername());
ord.setPid(c.getProduct().getId());
ord.setPname(c.getProduct().getName());
orderRepository.save(ord);
// OrderStatus orderStatus = new OrderStatus(ord, "PROCESS", "order placed succesfully in " + uid);
// template.convertAndSend(MessagingConfig.EXCHANGE, MessagingConfig.ROUTING_KEY, orderStatus);
}
cartRepository.deleteItems(uid);
}
@DeleteMapping("/orders/{oid}")
public void deleteFromOrder(@PathVariable("oid") Long oid) {
orderRepository.deleteById(oid);
}
}

75
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/44/00842108481c001c1175ef5c8fe3bc4a

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>UserService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>UserService</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

4
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/44/70bfdb841021001c12d2a58e3b8f44a0

@ -1,4 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

100
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/45/604c0e592920001c1fd4fcbaef3ed6f3

@ -1,100 +0,0 @@
package com.example.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class CartController {
@Autowired
private UserRepo userRepository;
@Autowired
private ProductRepo productRepository;
@Autowired
private CartRepo cartRepository;
@PostMapping("/cart/{uid}/{pid}")
public Cart postCart(@RequestBody Cart cart, @PathVariable("uid") Long uid, @PathVariable("pid") Long pid) {
Product product = productRepository.getById(pid);
User user = userRepository.getById(uid);
cart.setUser(user);
cart.setProduct(product);
int q=1;
cart.setQuantity(q);
cart.setTotalPrice(cart.getProduct().getPrice()*cart.getQuantity());
return cartRepository.save(cart);
}
@GetMapping("/cartdto/{uid}")
public List<CartDto> getCartdto(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
List<CartDto> listDto = new ArrayList<>();
list = cartRepository.findByUserId(uid);
for(Cart c : list) {
CartDto cartDto = new CartDto();
cartDto.setCid(c.getId());
cartDto.setQuantity(c.getQuantity());
cartDto.setTotalPrice(c.getQuantity()*c.getProduct().getPrice());
cartDto.setPid(c.getProduct().getId());
cartDto.setImag(c.getProduct().getImag());
cartDto.setName(c.getProduct().getName());
cartDto.setPrice(c.getProduct().getPrice());
cartDto.setUid(c.getUser().getId());
cartDto.setUsername(c.getUser().getUsername());
cartDto.setApartments(c.getUser().getApartments());
listDto.add(cartDto);
}
return listDto;
}
@GetMapping("/cart/{uid}")
public List<Cart> getCartByUser(@PathVariable("uid") Long uid) {
return cartRepository.findByUserId(uid);
}
@PostMapping("/cartquant/{cid}/{quantity}")
public Double addQuantity(@PathVariable("cid") Long cid, @PathVariable("quantity") Double quantity) {
Cart cart= cartRepository.getById(cid);
cart.setQuantity(quantity);
cart.setTotalPrice(quantity*cart.getProduct().getPrice());
cartRepository.save(cart);
return cart.getTotalPrice();
}
@PostMapping("/cartsum/{uid}")
public Double getCartSum(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
list = cartRepository.findByUserId(uid);
Cart cart = new Cart();
Double sum = 0.0;
for(Cart c : list) {
sum=sum+ c.getTotalPrice();
}
return sum;
}
@DeleteMapping("/cart/{cid}")
public void deleteFromCart(@PathVariable("cid") Long cid) {
cartRepository.deleteById(cid);
}
}

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/45/f0e96108ac1c001c1ceba011ddc7f939

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\resources\\generated.json");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

15
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/47/e077bf5d851c001c1e2b8f537ef912f3

@ -1,15 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
public interface UserService {
User saveUser(User user);
List<User> findAllAccounts();
User getUserById(Long id);
}

155
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/48/a0bd064d2c20001c1fd4fcbaef3ed6f3

@ -1,155 +0,0 @@
package com.example.demo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
@Entity
public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String password;
private String fullname;
private String gender;
private Long phone;
private String email;
private String address;
private String city;
private String state;
private int pincode;
private String apartments;
public User() {
super();
// TODO Auto-generated constructor stub
}
public User(String username, String email) {
super();
this.username = username;
this.email = email;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Long getPhone() {
return phone;
}
public void setPhone(Long phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getPincode() {
return pincode;
}
public void setPincode(int pincode) {
this.pincode = pincode;
}
public String getApartments() {
return apartments;
}
public void setApartments(String apartments) {
this.apartments = apartments;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<GrantedAuthority>list=new ArrayList<>();
SimpleGrantedAuthority sga = new SimpleGrantedAuthority(username);
list.add(sga);
return list;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}

25
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/48/f0c6588c811c001c1e2b8f537ef912f3

@ -1,25 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
}

69
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/4d/800c8463811c001c1e2b8f537ef912f3

@ -1,69 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
//@RequestMapping("/api/user")
public class UserController {
// static String URI = "/api/user/";
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@PostMapping("/user")
public Optional<User> postUser(@RequestBody User user) {
return userService.saveUser(user);
}
@GetMapping("/user")
public List<User> getAllAccounts(){
List<User> list = userService.findAllAccounts();
return list;
}
@GetMapping("/user/{id}")
public Optional<User> findUserById(@PathVariable("id") Long id) {
return userService.getUserById(id);
}
@PutMapping("/user/{id}")
public Optional<User> updateUser(@PathVariable("id") Long id,@RequestBody User newVal) {
User userDB = userService.getUserById(id);
userDB.setUsername(newVal.getUsername());
userDB.setFullname(newVal.getFullname());
userDB.setGender(newVal.getGender());
userDB.setPhone(newVal.getPhone());
userDB.setEmail(newVal.getEmail());
userDB.setAddress(newVal.getAddress());
userDB.setCity(newVal.getCity());
userDB.setState(newVal.getState());
userDB.setPincode(newVal.getPincode());
userDB.setApartments(newVal.getApartments());
return userService.saveUser(userDB);
}
}

27
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/4f/701e18e92a20001c1fd4fcbaef3ed6f3

@ -1,27 +0,0 @@
package com.example.demo.repository;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface CartRepo extends JpaRepository<Cart, Long> {
List<Cart> findByUserId(Long uid);
@Query("select c from Cart c join c.user u where u.id = ?1")
List<Cart> getItems(Long uid);
@Modifying
@Transactional
@Query("delete from Cart c where c.user.id=?1")
void deleteItems(Long uid);
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/50/f0f3b6ed7720001c1639f432a894b632

@ -1,13 +0,0 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CartServiceApplication {
public static void main(String[] args) {
SpringApplication.run(CartServiceApplication.class, args);
}
}

7
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/52/d0c0ed841021001c12d2a58e3b8f44a0

@ -1,7 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/53/a08945971d20001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo;
public class CartController {
}

25
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/55/d0287e097f1c001c1e2b8f537ef912f3

@ -1,25 +0,0 @@
package com.example.demo;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
@Override
public Optional<User> getUserById(long id) {
return userRepository.findById(id);
}
}

3
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/0072e4841021001c12d2a58e3b8f44a0

@ -1,3 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

65
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/200956c2811c001c1e2b8f537ef912f3

@ -1,65 +0,0 @@
package com.example.demo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
public class UserServiceTest {
@Mock
private UserRepo userRepository;
@InjectMocks
private UserServiceImpl userService;
private User m1 = new User("Paddy Welbourn", "pwelbourn0@ed.gov");
private User m2 = new User("Wren Flori", "wflori2@webeden.co.uk");
private User m3 = new User("Ambrosio Smewing", "asmewing4@hostgator.com");
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
m1.setId(1L);
m2.setId(2L);
m3.setId(3L);
}
@Test
public void testGetUserById() {
//given
given(userRepository.findById(1L)).willReturn(Optional.of(m1));
//calling method under the test
Optional<User> result = userService.getUserById(1L);
//assert
assertThat(result.isPresent()).isTrue();
//assert
assertUserFields(result.orElseGet(null));
//verify that repository was called
verify(userRepository, times(1)).findById(1L);
}
private void assertUserFields(User user) {
assertThat(user.getId()).isInstanceOf(Long.class);
assertThat(user.getId()).isEqualTo(1);
assertThat(user.getUsername()).isEqualTo("Paddy Welbourn");
assertThat(user.getEmail()).isEqualTo("pwelbourn0@ed.gov");
}
}

32
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/a05d59007220001c1639f432a894b632

@ -1,32 +0,0 @@
package hello
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
class LoadTest extends Simulation {
val httpProtocol: HttpProtocolBuilder = http
.baseUrl("http://localhost:59277")
object HelloWorldResource {
val get: ChainBuilder = exec(http("HelloWorld")
.get("/")
.basicAuth("user", "24gh39ugh0"))
}
val myScenario: ScenarioBuilder = scenario("RampUpUsers")
.exec(HelloWorldResource.get)
setUp(myScenario.inject(
incrementUsersPerSec(20)
.times(5)
.eachLevelLasting(5 seconds)
.separatedByRampsLasting(5 seconds)
.startingFrom(20)
)).protocols(httpProtocol)
.assertions(global.successfulRequests.percent.is(100))
}

2
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/57/d07e1f101e20001c1fd4fcbaef3ed6f3

@ -1,2 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/58/4095b7f2a21c001c1afc8a1edde7498c

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/59/704ab3ed7720001c1639f432a894b632

@ -1,13 +0,0 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}

8
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5d/a0d1214d2a20001c1fd4fcbaef3ed6f3

@ -1,8 +0,0 @@
package com.example.demo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OrderRepo extends JpaRepository<Orders, Long> {
}

32
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5d/c03add7fe420001c1ad9f76e81c64a6c

@ -1,32 +0,0 @@
package hello
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
class LoadTest extends Simulation {
val httpProtocol: HttpProtocolBuilder = http
.baseUrl("http://localhost:5007")
object HelloWorldResource {
val get: ChainBuilder = exec(http("Logging on")
.get("/userapi/login")
.basicAuth("nitya", "jain"))
}
val myScenario: ScenarioBuilder = scenario("RampUpUsers")
.exec(HelloWorldResource.get)
setUp(myScenario.inject(
incrementUsersPerSec(1)
.times(1)
.eachLevelLasting(5 seconds)
.separatedByRampsLasting(5 seconds)
.startingFrom(1)
)).protocols(httpProtocol)
.assertions(global.successfulRequests.percent.is(100))
}

23
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5e/c07c6cc9ba1b001c1da2ffc18848673d

@ -1,23 +0,0 @@
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private final UserRepo userRepository;
@Autowired
public UserServiceImpl(UserRepo userRepository) {
this.userRepository = userRepository;
}
@Override
public User getUserById(long id) {
return userRepository.findById(id);
}
}

8
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5e/e00befd31a20001c1fd4fcbaef3ed6f3

@ -1,8 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

90
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/00ce31622620001c1fd4fcbaef3ed6f3

@ -1,90 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import java.security.Principal;
import java.util.Base64;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
//@RequestMapping("/api/user")
public class UserController {
// static String URI = "/api/user/";
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@PostMapping("/signup")
public User postUser(@RequestBody User user) {
String code = user.getUsername();
String username = new String(Base64.getDecoder().decode(code)).split(":")[0];
String password = new String(Base64.getDecoder().decode(code)).split(":")[1];
user.setUsername(username);
user.setPassword(password);
String encPassword = passwordEncoder.encode(user.getPassword());
user.setPassword(encPassword);
return userRepository.save(user);
}
@GetMapping("/login")
public Principal login(Principal principal) {
if(principal.getName()==null)
throw new Error("Invalid Credentials");
return principal;
}
@GetMapping("/user")
public List<User> getAllAccounts(){
List<User> list = userService.findAllAccounts();
return list;
}
@GetMapping("/user/{id}")
public Optional<User> findUserById(@PathVariable("id") Long id) {
return userService.getUserById(id);
}
@GetMapping("/username/{username}")
public User getDetails(@PathVariable("username") String username) {
return userService.getByUsername(username);
}
@PutMapping("/user/{id}")
public User updateUser(@PathVariable("id") Long id,@RequestBody User newVal) {
User userDB = userService.getUsersById(id);
userDB.setUsername(newVal.getUsername());
userDB.setFullname(newVal.getFullname());
userDB.setGender(newVal.getGender());
userDB.setPhone(newVal.getPhone());
userDB.setEmail(newVal.getEmail());
userDB.setAddress(newVal.getAddress());
userDB.setCity(newVal.getCity());
userDB.setState(newVal.getState());
userDB.setPincode(newVal.getPincode());
userDB.setApartments(newVal.getApartments());
return userService.saveUser(userDB);
}
}

3
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/b0a121101e20001c1fd4fcbaef3ed6f3

@ -1,3 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/b0fc4cada81c001c15eabe5cf52659ba

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\resources");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

8
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c00af0841021001c12d2a58e3b8f44a0

@ -1,8 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

65
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6/b06d5c0f801c001c1e2b8f537ef912f3

@ -1,65 +0,0 @@
package com.example.demo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
public class UserServiceTest {
@Mock
private UserRepo userRepository;
@InjectMocks
private UserServiceImpl userService;
private User m1 = new User("Paddy Welbourn", "pwelbourn0@ed.gov");
private User m2 = new User("Wren Flori", "wflori2@webeden.co.uk");
private User m3 = new User("Ambrosio Smewing", "asmewing4@hostgator.com");
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
m1.setId(1L);
m2.setId(2L);
m3.setId(3L);
}
@Test
public void testGetUserById() {
//given
given(userRepository.findById(1L)).willReturn(Optional.of(m1));
//calling method under the test
Optional<User> result = userService.getUserById(1L);
//assert
assertThat(result.isPresent()).isTrue();
//assert
assertUserFields(result.orElseGet(null));
//verify that repository was called
verify(userRepository, times(1)).findById(1L);
}
private void assertUserFields(User user) {
assertThat(user.getId()).isInstanceOf(Long.class);
assertThat(user.getId()).isEqualTo(1);
assertThat(user.getUsername()).isEqualTo("Paddy Welbourn");
assertThat(user.getEmail()).isEqualTo("pwelbourn0@ed.gov");
}
}

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/60/809f5596a81c001c15eabe5cf52659ba

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\resources\\static");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/61/d0dafdfe6a22001c17d1e4ac7a211a08

@ -1,13 +0,0 @@
server.port=5007
spring.datasource.url=jdbc:mysql://10.3.117.23:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/userapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

69
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/63/50d1ae58861c001c1e2b8f537ef912f3

@ -1,69 +0,0 @@
package com.example.demo;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
//@RequestMapping("/api/user")
public class UserController {
// static String URI = "/api/user/";
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@PostMapping("/user")
public User postUser(@RequestBody User user) {
return userService.saveUser(user);
}
@GetMapping("/user")
public List<User> getAllAccounts(){
List<User> list = userService.findAllAccounts();
return list;
}
@GetMapping("/user/{id}")
public User findUserById(@PathVariable("id") Long id) {
return userService.getUserById(id);
}
@PutMapping("/user/{id}")
public User updateUser(@PathVariable("id") Long id,@RequestBody User newVal) {
User userDB = userService.getUserById(id);
userDB.setUsername(newVal.getUsername());
userDB.setFullname(newVal.getFullname());
userDB.setGender(newVal.getGender());
userDB.setPhone(newVal.getPhone());
userDB.setEmail(newVal.getEmail());
userDB.setAddress(newVal.getAddress());
userDB.setCity(newVal.getCity());
userDB.setState(newVal.getState());
userDB.setPincode(newVal.getPincode());
userDB.setApartments(newVal.getApartments());
return userService.saveUser(userDB);
}
}

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/65/5076df81a51c001c18e2b55ca6c81bda

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\resources");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

54
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/65/70a90d754a1c001c1175ef5c8fe3bc4a

@ -1,54 +0,0 @@
package com.example.demo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = UserServiceApplication.class)
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UserControllerTest {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void shouldFindMemberById() throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.get("/userapi/user" + "2")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(jsonPath("$.id").exists())
.andExpect(jsonPath("$.id").value(2))
.andExpect(jsonPath("$.name").exists())
.andExpect(jsonPath("$.name").value("Mary Brown"))
.andExpect(jsonPath("$.email").value("mary.b@gmail.com"))
.andExpect(jsonPath("$.*", hasSize(3)))
.andReturn();
}
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/66/c0a652ed1d20001c1fd4fcbaef3ed6f3

@ -1,5 +0,0 @@
package com.example.demo;
public class CartDto {
}

5
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/68/50d2b89c7c22001c17d1e4ac7a211a08

@ -1,5 +0,0 @@
package com.example.demo.model;
public class OrderDto {
}

13
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/68/e0ee4a8daf1a001c19bcf3b7e4125f31

@ -1,13 +0,0 @@
server.port=5002
spring.datasource.url=jdbc:mysql://10.3.117.30:3306/grocery_59277?createDatabaseIfNotExist=true
spring.datasource.username=grocery_59277_user
spring.datasource.password=PASSWORD123
server.servlet.context-path=/productapi
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false

74
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6a/20a559847620001c1639f432a894b632

@ -1,74 +0,0 @@
package com.example.demo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class ProductServiceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ProductServiceApplication.class, args);
}
@Override
public void run(String... args) throws Exception{
URL url = new URL ("http://localhost:5008/productapi/product");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//JSON String need to be constructed for the specific resource.
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
// String jsonInputString = "{\"category\": \"Fruits\", \"imag\": \"applepic\", \"name\": \"apple\", \"price\": \"20\" }";
try(OutputStream os = con.getOutputStream()){
// byte[] input = jsonInputString.getBytes("utf-8");
byte[] input = readFile("C:\\Users\\59277\\workgroup\\springboot\\ProductService\\src\\main\\resources\\generated.json");
os.write(input, 0, input.length);
}
int code = con.getResponseCode();
System.out.println(code);
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
}
public static byte[] readFile(String file) throws IOException {
File f = new File(file);
byte[] buffer = new byte[(int)f.length()];
FileInputStream is = new FileInputStream(file);
is.read(buffer);
is.close();
// TODO Auto-generated method stub
return buffer;
}
}

4
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6c/600fe4d31a20001c1fd4fcbaef3ed6f3

@ -1,4 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

65
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/6d/2094d5f92720001c1fd4fcbaef3ed6f3

@ -1,65 +0,0 @@
package com.example.demo.securityfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private MyUserDetailsService myUserDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
// .antMatchers("/home").authenticated()
// .antMatchers("/account").hasAnyAuthority("ADMIN")
.antMatchers("/home").permitAll()
.antMatchers("/account").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/signup").permitAll()
.antMatchers("/products").permitAll()
.and()
.httpBasic();
http.cors();
http.csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.authenticationProvider(getAuthenticator());
}
private DaoAuthenticationProvider getAuthenticator() {
DaoAuthenticationProvider dao = new DaoAuthenticationProvider();
dao.setUserDetailsService(myUserDetailsService);
dao.setPasswordEncoder(getPasswordEncoder());
return dao;
}
@Primary
@Bean
public PasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}

100
springboot_backend/.metadata/.plugins/org.eclipse.core.resources/.history/7/e084e6cd2820001c1fd4fcbaef3ed6f3

@ -1,100 +0,0 @@
package com.example.demo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin(origins = "http://localhost:17599",
methods = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT})
public class CartController {
@Autowired
private UserRepo userRepository;
@Autowired
private ProductRepo productRepository;
@Autowired
private CartRepo cartRepository;
@PostMapping("/cart/{uid}/{pid}")
public Cart postCart(@RequestBody Cart cart, @PathVariable("uid") Long uid, @PathVariable("pid") Long pid) {
Product product = productRepository.getById(pid);
User user = userRepository.getById(uid);
cart.setUser(user);
cart.setProduct(product);
int q=1;
cart.setQuantity(q);
cart.setTotalPrice(cart.getProduct().getPrice()*cart.getQuantity());
return cartRepository.save(cart);
}
@GetMapping("/cartdto/{uid}")
public List<CartDto> getCartdto(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
List<CartDto> listDto = new ArrayList<>();
list = cartRepository.findByUserId(uid);
for(Cart c : list) {
CartDto cartDto = new CartDto();
cartDto.setCid(c.getId());
cartDto.setQuantity(c.getQuantity());
cartDto.setTotalPrice(c.getQuantity()*c.getProduct().getPrice());
cartDto.setPid(c.getProduct().getId());
cartDto.setImag(c.getProduct().getImag());
cartDto.setName(c.getProduct().getName());
cartDto.setPrice(c.getProduct().getPrice());
cartDto.setUid(c.getUser().getId());
cartDto.setUsername(c.getUser().getUsername());
cartDto.setApartments(c.getUser().getApartments());
listDto.add(cartDto);
}
return listDto;
}
@GetMapping("/cart/{uid}")
public List<Cart> getCartByUser(@PathVariable("uid") Long uid) {
return cartRepository.findByUserId(uid);
}
@PostMapping("/cartquant/{cid}/{quantity}")
public Double addQuantity(@PathVariable("cid") Long cid, @PathVariable("quantity") Double quantity) {
Cart cart= cartRepository.getById(cid);
cart.setQuantity(quantity);
cart.setTotalPrice(quantity*cart.getProduct().getPrice());
cartRepository.save(cart);
return cart.getTotalPrice();
}
@PostMapping("/cartsum/{uid}")
public Double getCartSum(@PathVariable("uid") Long uid) {
List<Cart> list = new ArrayList<>();
list = cartRepository.findByUserId(uid);
Cart cart = new Cart();
Double sum = 0.0;
for(Cart c : list) {
sum=sum+ c.getTotalPrice();
}
return sum;
}
@DeleteMapping("/cart/{cid}")
public void deleteFromCart(@PathVariable("cid") Long cid) {
cartRepository.deleteById(cid);
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save