├── README.md ├── order-service ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── order │ │ │ ├── repo │ │ │ └── OrderRepository.java │ │ │ ├── ApplicationMain.java │ │ │ ├── dto │ │ │ ├── CancelOrderRequest.java │ │ │ ├── CancelOrderResponse.java │ │ │ ├── PlaceOrderRequest.java │ │ │ └── PlaceOrderResponse.java │ │ │ ├── controller │ │ │ └── OrderController.java │ │ │ ├── entity │ │ │ └── Orders.java │ │ │ └── services │ │ │ └── OrderService.java │ │ └── resources │ │ └── application.properties └── pom.xml ├── .gitignore ├── product-service ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── product │ │ │ ├── ApplicationMain.java │ │ │ ├── repo │ │ │ └── ProductsRepository.java │ │ │ ├── config │ │ │ ├── CustomBeans.java │ │ │ └── JacksonConfig.java │ │ │ ├── dto │ │ │ ├── ProductRequest.java │ │ │ ├── ProductData.java │ │ │ └── ProductResponse.java │ │ │ ├── entity │ │ │ └── Products.java │ │ │ ├── controller │ │ │ └── ProductController.java │ │ │ └── services │ │ │ └── ProductService.java │ │ └── resources │ │ └── application.properties └── pom.xml └── authentication-service ├── src └── main │ ├── java │ └── org │ │ └── users │ │ ├── ApplicationMain.java │ │ ├── config │ │ ├── CustomBeans.java │ │ └── JacksonConfig.java │ │ ├── dto │ │ ├── LoginResponse.java │ │ ├── LoginRequest.java │ │ ├── UserRequest.java │ │ ├── UserData.java │ │ └── UserResponse.java │ │ ├── repo │ │ └── UsersRepository.java │ │ ├── controller │ │ ├── LoginController.java │ │ └── UserManagementController.java │ │ ├── services │ │ ├── LoginService.java │ │ └── UserManagementService.java │ │ └── entity │ │ └── Users.java │ └── resources │ └── application.properties └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | # Shopping Management API 2 | A Real Time Shopping Management API made with Spring Boot for Request-Response Communication. 3 | Supports 3 Services naming 4 | 1->authentication-service 5 | 2->product-service 6 | 3->order-service. 7 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/repo/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package org.order.repo; 2 | 3 | import org.order.entity.Orders; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface OrderRepository extends JpaRepository { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/ApplicationMain.java: -------------------------------------------------------------------------------- 1 | package org.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ApplicationMain { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ApplicationMain.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/dto/CancelOrderRequest.java: -------------------------------------------------------------------------------- 1 | package org.order.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class CancelOrderRequest { 7 | private Long orderId; 8 | 9 | public Long getOrderId() { 10 | return orderId; 11 | } 12 | 13 | public void setOrderId(Long orderId) { 14 | this.orderId = orderId; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | /bin 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/ApplicationMain.java: -------------------------------------------------------------------------------- 1 | package org.product; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ApplicationMain { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ApplicationMain.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/ApplicationMain.java: -------------------------------------------------------------------------------- 1 | package org.users; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ApplicationMain { 8 | 9 | public static void main(String[] args) { 10 | 11 | SpringApplication.run(ApplicationMain.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/repo/ProductsRepository.java: -------------------------------------------------------------------------------- 1 | package org.product.repo; 2 | 3 | import org.product.entity.Products; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | @Component 10 | public interface ProductsRepository extends JpaRepository{ 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8083 2 | 3 | spring.datasource.url=jdbc:mysql://localhost:3306/order_service_db?allowPublicKeyRetrieval=true&useSSL=false 4 | spring.profile.active=mysql 5 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 6 | spring.datasource.username=saas 7 | spring.datasource.password=Test@1234 8 | spring.jpa.hibernate.ddl-auto=create 9 | spring.jpa.show-sql=true 10 | spring.jpa.properties.hibernate.format_sql=true -------------------------------------------------------------------------------- /product-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | 3 | spring.datasource.url=jdbc:mysql://localhost:3306/product_service_db?allowPublicKeyRetrieval=true&useSSL=false 4 | spring.profile.active=mysql 5 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 6 | spring.datasource.username=saas 7 | spring.datasource.password=Test@1234 8 | spring.jpa.hibernate.ddl-auto=create 9 | spring.jpa.show-sql=true 10 | spring.jpa.properties.hibernate.format_sql=true -------------------------------------------------------------------------------- /authentication-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | 3 | spring.datasource.url=jdbc:mysql://localhost:3306/authentication_service_db?allowPublicKeyRetrieval=true&useSSL=false 4 | spring.profile.active=mysql 5 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 6 | spring.datasource.username=saas 7 | spring.datasource.password=Test@1234 8 | spring.jpa.hibernate.ddl-auto=create 9 | spring.jpa.show-sql=true 10 | spring.jpa.properties.hibernate.format_sql=true -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/config/CustomBeans.java: -------------------------------------------------------------------------------- 1 | package org.product.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class CustomBeans { 11 | @Bean 12 | public List longListBean() { 13 | return new ArrayList(); 14 | } 15 | 16 | @Bean 17 | public List stringListBean() { 18 | return new ArrayList(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/config/CustomBeans.java: -------------------------------------------------------------------------------- 1 | package org.users.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | public class CustomBeans { 11 | @Bean 12 | public List longListBean() { 13 | return new ArrayList(); 14 | } 15 | 16 | @Bean 17 | public List stringListBean() { 18 | return new ArrayList(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/dto/LoginResponse.java: -------------------------------------------------------------------------------- 1 | package org.users.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class LoginResponse { 7 | private String status; 8 | private String message; 9 | 10 | public String getStatus() { 11 | return status; 12 | } 13 | 14 | public void setStatus(String status) { 15 | this.status = status; 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public void setMessage(String message) { 23 | this.message = message; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/dto/CancelOrderResponse.java: -------------------------------------------------------------------------------- 1 | package org.order.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class CancelOrderResponse { 7 | private Long orderId; 8 | private String message; 9 | 10 | public Long getOrderId() { 11 | return orderId; 12 | } 13 | 14 | public void setOrderId(Long orderId) { 15 | this.orderId = orderId; 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public void setMessage(String message) { 23 | this.message = message; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/dto/LoginRequest.java: -------------------------------------------------------------------------------- 1 | package org.users.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class LoginRequest { 7 | private String username; 8 | private String password; 9 | 10 | public String getUsername() { 11 | return username; 12 | } 13 | 14 | public void setUsername(String username) { 15 | this.username = username; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/dto/PlaceOrderRequest.java: -------------------------------------------------------------------------------- 1 | package org.order.dto; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class PlaceOrderRequest { 9 | 10 | private List productIds; 11 | private int quantity; 12 | 13 | public List getProductIds() { 14 | return productIds; 15 | } 16 | 17 | public void setProductIds(List productIds) { 18 | this.productIds = productIds; 19 | } 20 | 21 | public int getQuantity() { 22 | return quantity; 23 | } 24 | 25 | public void setQuantity(int quantity) { 26 | this.quantity = quantity; 27 | } 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package org.users.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 6 | 7 | import com.fasterxml.jackson.annotation.JsonInclude; 8 | 9 | @Configuration 10 | public class JacksonConfig { 11 | 12 | @Bean 13 | public Jackson2ObjectMapperBuilder objectMapperBuilder() { 14 | Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); 15 | builder.serializationInclusion(JsonInclude.Include.NON_NULL); 16 | return builder; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package org.product.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 6 | 7 | import com.fasterxml.jackson.annotation.JsonInclude; 8 | 9 | @Configuration 10 | public class JacksonConfig { 11 | 12 | @Bean 13 | public Jackson2ObjectMapperBuilder objectMapperBuilder() { 14 | Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); 15 | builder.serializationInclusion(JsonInclude.Include.NON_NULL); 16 | return builder; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/repo/UsersRepository.java: -------------------------------------------------------------------------------- 1 | package org.users.repo; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.stereotype.Repository; 8 | import org.users.entity.Users; 9 | 10 | @Repository 11 | @Component 12 | public interface UsersRepository extends JpaRepository { 13 | 14 | List findByUsernameAndPassword(String username, String password); 15 | 16 | List findByEmail(String email); 17 | 18 | List findByAge(String age); 19 | 20 | List findByUsername(String username); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/dto/ProductRequest.java: -------------------------------------------------------------------------------- 1 | package org.product.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class ProductRequest { 7 | 8 | private String productName; 9 | private int price; 10 | private int quantity; 11 | 12 | public String getProductName() { 13 | return productName; 14 | } 15 | 16 | public void setProductName(String productName) { 17 | this.productName = productName; 18 | } 19 | 20 | public int getPrice() { 21 | return price; 22 | } 23 | 24 | public void setPrice(int price) { 25 | this.price = price; 26 | } 27 | 28 | public int getQuantity() { 29 | return quantity; 30 | } 31 | 32 | public void setQuantity(int quantity) { 33 | this.quantity = quantity; 34 | } 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/dto/PlaceOrderResponse.java: -------------------------------------------------------------------------------- 1 | package org.order.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class PlaceOrderResponse { 7 | 8 | private Long orderId; 9 | 10 | private double totalPrice; 11 | private String message; 12 | 13 | public Long getOrderId() { 14 | return orderId; 15 | } 16 | 17 | public void setOrderId(Long orderId) { 18 | this.orderId = orderId; 19 | } 20 | 21 | public double getTotalPrice() { 22 | return totalPrice; 23 | } 24 | 25 | public void setTotalPrice(double totalPrice) { 26 | this.totalPrice = totalPrice; 27 | } 28 | 29 | public String getMessage() { 30 | return message; 31 | } 32 | 33 | public void setMessage(String message) { 34 | this.message = message; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/dto/ProductData.java: -------------------------------------------------------------------------------- 1 | package org.product.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | 7 | @Component 8 | @JsonInclude(JsonInclude.Include.NON_NULL) 9 | public class ProductData { 10 | 11 | private String productName; 12 | private int price; 13 | private int quantity; 14 | 15 | public String getProductName() { 16 | return productName; 17 | } 18 | 19 | public void setProductName(String productName) { 20 | this.productName = productName; 21 | } 22 | 23 | public int getPrice() { 24 | return price; 25 | } 26 | 27 | public void setPrice(int price) { 28 | this.price = price; 29 | } 30 | 31 | public int getQuantity() { 32 | return quantity; 33 | } 34 | 35 | public void setQuantity(int quantity) { 36 | this.quantity = quantity; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package org.users.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.users.dto.LoginRequest; 8 | import org.users.dto.LoginResponse; 9 | import org.users.services.LoginService; 10 | 11 | @RestController 12 | public class LoginController { 13 | 14 | @Autowired 15 | LoginService loginService; 16 | 17 | @PostMapping(path = "/api/v1/validate", consumes = { "application/json", "application/xml" }, produces = { 18 | "application/json", "application/xml" }) 19 | public LoginResponse validate(@RequestBody LoginRequest loginRequest) { 20 | 21 | return loginService.validateUser(loginRequest); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/dto/UserRequest.java: -------------------------------------------------------------------------------- 1 | package org.users.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class UserRequest { 7 | 8 | private String username; 9 | private String password; 10 | private String email; 11 | private String age; 12 | 13 | public String getUsername() { 14 | return username; 15 | } 16 | 17 | public void setUsername(String username) { 18 | this.username = username; 19 | } 20 | 21 | public String getPassword() { 22 | return password; 23 | } 24 | 25 | public void setPassword(String password) { 26 | this.password = password; 27 | } 28 | 29 | public String getEmail() { 30 | return email; 31 | } 32 | 33 | public void setEmail(String email) { 34 | this.email = email; 35 | } 36 | 37 | public String getAge() { 38 | return age; 39 | } 40 | 41 | public void setAge(String age) { 42 | this.age = age; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/services/LoginService.java: -------------------------------------------------------------------------------- 1 | package org.users.services; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.users.dto.LoginRequest; 8 | import org.users.dto.LoginResponse; 9 | import org.users.entity.Users; 10 | import org.users.repo.UsersRepository; 11 | 12 | @Service 13 | public class LoginService { 14 | 15 | @Autowired 16 | UsersRepository userRepo; 17 | 18 | public LoginResponse validateUser(LoginRequest loginRequest) { 19 | 20 | LoginResponse response = new LoginResponse(); 21 | 22 | List liuser = userRepo.findByUsernameAndPassword(loginRequest.getUsername(), loginRequest.getPassword()); 23 | 24 | if (liuser.size() == 1) { 25 | response.setStatus("Success"); 26 | response.setMessage("Login Successful"); 27 | } else { 28 | response.setStatus("Fail"); 29 | response.setMessage("Login Failed!"); 30 | } 31 | return response; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/dto/UserData.java: -------------------------------------------------------------------------------- 1 | package org.users.dto; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | 7 | @Component 8 | @JsonInclude(JsonInclude.Include.NON_NULL) 9 | public class UserData { 10 | 11 | private String username; 12 | private String password; 13 | private String email; 14 | private String age; 15 | 16 | public String getUsername() { 17 | return username; 18 | } 19 | 20 | public void setUsername(String username) { 21 | this.username = username; 22 | } 23 | 24 | public String getPassword() { 25 | return password; 26 | } 27 | 28 | public void setPassword(String password) { 29 | this.password = password; 30 | } 31 | 32 | public String getEmail() { 33 | return email; 34 | } 35 | 36 | public void setEmail(String email) { 37 | this.email = email; 38 | } 39 | 40 | public String getAge() { 41 | return age; 42 | } 43 | 44 | public void setAge(String age) { 45 | this.age = age; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/dto/ProductResponse.java: -------------------------------------------------------------------------------- 1 | package org.product.dto; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class ProductResponse { 8 | 9 | private String status; 10 | private String message; 11 | private Long productId; 12 | 13 | @Autowired 14 | public ProductData productData; 15 | 16 | public ProductData getProductData() { 17 | return productData; 18 | } 19 | 20 | public void setProductData(ProductData productData) { 21 | this.productData = productData; 22 | } 23 | 24 | public String getStatus() { 25 | return status; 26 | } 27 | 28 | public void setStatus(String status) { 29 | this.status = status; 30 | } 31 | 32 | public String getMessage() { 33 | return message; 34 | } 35 | 36 | public void setMessage(String message) { 37 | this.message = message; 38 | } 39 | 40 | public Long getProductId() { 41 | return productId; 42 | } 43 | 44 | public void setProductId(Long productId) { 45 | this.productId = productId; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/dto/UserResponse.java: -------------------------------------------------------------------------------- 1 | package org.users.dto; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | import com.fasterxml.jackson.annotation.JsonInclude; 6 | 7 | @JsonInclude(JsonInclude.Include.NON_NULL) 8 | @Component 9 | public class UserResponse { 10 | 11 | private String status; 12 | private String message; 13 | private long userId; 14 | 15 | @Autowired 16 | public UserData userData; 17 | 18 | public UserData getUserData() { 19 | return userData; 20 | } 21 | 22 | public void setUserData(UserData userData) { 23 | this.userData = userData; 24 | } 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | 34 | public String getMessage() { 35 | return message; 36 | } 37 | 38 | public void setMessage(String message) { 39 | this.message = message; 40 | } 41 | 42 | public long getUserId() { 43 | return userId; 44 | } 45 | 46 | public void setUserId(long userId) { 47 | this.userId = userId; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package org.order.controller; 2 | 3 | import org.order.dto.CancelOrderResponse; 4 | import org.order.dto.PlaceOrderRequest; 5 | import org.order.dto.PlaceOrderResponse; 6 | import org.order.services.OrderService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | @RestController 15 | public class OrderController { 16 | 17 | 18 | @Autowired 19 | OrderService orderServices; 20 | 21 | @PostMapping(path = "/api/v1/order") 22 | public PlaceOrderResponse orderService(@RequestBody PlaceOrderRequest orderRequest) { 23 | return orderServices.placeOrder(orderRequest); 24 | 25 | } 26 | @DeleteMapping(path="/api/v1/order/{orderId}") 27 | public CancelOrderResponse cancelOrder(@PathVariable Long orderId) { 28 | return orderServices.cancelOrder(orderId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/entity/Products.java: -------------------------------------------------------------------------------- 1 | package org.product.entity; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import jakarta.persistence.Column; 6 | import jakarta.persistence.Entity; 7 | import jakarta.persistence.GeneratedValue; 8 | import jakarta.persistence.Id; 9 | import jakarta.persistence.Table; 10 | 11 | @Entity 12 | @Component 13 | @Table 14 | public class Products { 15 | 16 | @GeneratedValue 17 | @Id 18 | @Column 19 | private Long productId; 20 | 21 | @Column 22 | private String productName; 23 | 24 | @Column 25 | private int price; 26 | 27 | @Column 28 | private int quantity; 29 | 30 | public Long getProductId() { 31 | return productId; 32 | } 33 | 34 | public void setProductId(Long productId) { 35 | this.productId = productId; 36 | } 37 | 38 | public String getProductName() { 39 | return productName; 40 | } 41 | 42 | public void setProductName(String productName) { 43 | this.productName = productName; 44 | } 45 | 46 | public int getPrice() { 47 | return price; 48 | } 49 | 50 | public void setPrice(int price) { 51 | this.price = price; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/entity/Orders.java: -------------------------------------------------------------------------------- 1 | package org.order.entity; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.stereotype.Component; 6 | 7 | import jakarta.persistence.Column; 8 | import jakarta.persistence.Entity; 9 | import jakarta.persistence.GeneratedValue; 10 | import jakarta.persistence.Id; 11 | import jakarta.persistence.Table; 12 | 13 | @Entity 14 | @Table 15 | @Component 16 | public class Orders { 17 | 18 | @GeneratedValue 19 | @Id 20 | @Column 21 | private Long orderId; 22 | @Column 23 | private List productIds; 24 | @Column 25 | private int quantity; 26 | @Column 27 | private double price; 28 | 29 | public Long getOrderId() { 30 | return orderId; 31 | } 32 | 33 | public void setOrderId(Long orderId) { 34 | this.orderId = orderId; 35 | } 36 | 37 | public List getProductIds() { 38 | return productIds; 39 | } 40 | 41 | public void setProductIds(List productIds) { 42 | this.productIds = productIds; 43 | } 44 | 45 | public int getQuantity() { 46 | return quantity; 47 | } 48 | 49 | public void setQuantity(int quantity) { 50 | this.quantity = quantity; 51 | } 52 | 53 | public double getPrice() { 54 | return price; 55 | } 56 | 57 | public void setPrice(double price) { 58 | this.price = price; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/entity/Users.java: -------------------------------------------------------------------------------- 1 | package org.users.entity; 2 | 3 | import org.springframework.stereotype.Component; 4 | import jakarta.persistence.Column; 5 | import jakarta.persistence.Entity; 6 | import jakarta.persistence.GeneratedValue; 7 | import jakarta.persistence.Id; 8 | import jakarta.persistence.Table; 9 | 10 | @Entity 11 | @Component 12 | @Table 13 | public class Users { 14 | 15 | @Column 16 | @GeneratedValue 17 | @Id 18 | private long userId; 19 | 20 | @Column 21 | private String username; 22 | 23 | @Column 24 | private String password; 25 | 26 | @Column 27 | private String email; 28 | 29 | @Column 30 | private String age; 31 | 32 | public long getUserId() { 33 | return userId; 34 | } 35 | 36 | public void setUserId(long userId) { 37 | this.userId = userId; 38 | } 39 | 40 | public String getUserName() { 41 | return username; 42 | } 43 | 44 | public void setUserName(String username) { 45 | this.username = username; 46 | } 47 | 48 | public String getPassword() { 49 | return password; 50 | } 51 | 52 | public void setPassword(String password) { 53 | this.password = password; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | public String getAge() { 65 | return age; 66 | } 67 | 68 | public void setAge(String age) { 69 | this.age = age; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.dnyanyog 4 | order-service 5 | 0.0.1-SNAPSHOT 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.2.0 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | com.fasterxml.jackson.dataformat 22 | jackson-dataformat-xml 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-data-jpa 28 | 29 | 30 | mysql 31 | mysql-connector-java 32 | 8.0.33 33 | 34 | 35 | javax.persistence 36 | javax.persistence-api 37 | 2.2 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /product-service/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | org.dnyanyog 6 | product-service 7 | 0.0.1-SNAPSHOT 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 3.2.0 12 | 13 | 14 | 17 15 | 17 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-web 21 | 22 | 23 | com.fasterxml.jackson.dataformat 24 | jackson-dataformat-xml 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | 8.0.33 35 | 36 | 37 | javax.persistence 38 | javax.persistence-api 39 | 2.2 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /authentication-service/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | org.dnyanyog 6 | authentication-service 7 | 0.0.1-SNAPSHOT 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 3.2.0 12 | 13 | 14 | 17 15 | 17 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-web 21 | 22 | 23 | com.fasterxml.jackson.dataformat 24 | jackson-dataformat-xml 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | 8.0.33 35 | 36 | 37 | javax.persistence 38 | javax.persistence-api 39 | 2.2 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/controller/UserManagementController.java: -------------------------------------------------------------------------------- 1 | package org.users.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.DeleteMapping; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.users.dto.UserRequest; 13 | import org.users.dto.UserResponse; 14 | import org.users.services.UserManagementService; 15 | 16 | @RestController 17 | public class UserManagementController { 18 | 19 | @Autowired 20 | UserManagementService userService; 21 | 22 | @PostMapping(path = "/api/v1/user", consumes = { "application/json", "application/xml" }, produces = { 23 | "application/json", "application/xml" }) 24 | public UserResponse adduser(@RequestBody UserRequest addUserRequest) { 25 | return userService.adduser(addUserRequest); 26 | 27 | } 28 | 29 | @GetMapping(path = "/api/v1/user/{userId}") 30 | public UserResponse getSingleUser(@PathVariable Long userId) { 31 | return userService.getSingleUser(userId); 32 | } 33 | 34 | @GetMapping(path = "/api/v1/user") 35 | public List getAllUsers() { 36 | return userService.getAllUserIds(); 37 | } 38 | 39 | @DeleteMapping(path = "/api/v1/user/{userId}") 40 | public UserResponse deleteSingleUser(@PathVariable Long userId) { 41 | return userService.deleteUser(userId); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /order-service/src/main/java/org/order/services/OrderService.java: -------------------------------------------------------------------------------- 1 | package org.order.services; 2 | 3 | import java.util.Optional; 4 | 5 | import org.order.dto.CancelOrderResponse; 6 | import org.order.dto.PlaceOrderRequest; 7 | import org.order.dto.PlaceOrderResponse; 8 | import org.order.entity.Orders; 9 | import org.order.repo.OrderRepository; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | @Service 14 | public class OrderService { 15 | 16 | @Autowired 17 | OrderRepository orderRepo; 18 | 19 | public PlaceOrderResponse placeOrder(PlaceOrderRequest request) { 20 | 21 | PlaceOrderResponse response = new PlaceOrderResponse(); 22 | 23 | Orders orderTable = new Orders(); 24 | 25 | orderTable.setProductIds(request.getProductIds()); 26 | orderTable.setQuantity(request.getQuantity()); 27 | 28 | orderTable = orderRepo.save(orderTable); 29 | response.setTotalPrice( 30 | OrderService.this.totalPrice(orderTable.getQuantity(), orderTable.getPrice(), orderTable.getOrderId())); 31 | response.setMessage("Ordered Placed Successfully"); 32 | response.setOrderId(orderTable.getOrderId()); 33 | 34 | return response; 35 | } 36 | 37 | public CancelOrderResponse cancelOrder(Long orderId) { 38 | 39 | CancelOrderResponse response = new CancelOrderResponse(); 40 | 41 | Optional orderToDelete = orderRepo.findById(orderId); 42 | 43 | if (orderToDelete.isEmpty()) { 44 | response.setMessage("No Order Found for Cancellation with ID " + orderId); 45 | } else { 46 | Orders order = orderToDelete.get(); 47 | orderRepo.delete(order); 48 | response.setOrderId(order.getOrderId()); 49 | response.setMessage("Order cancelled Successfully"); 50 | } 51 | return response; 52 | } 53 | 54 | public double totalPrice(int quantity, double price, Long orderId) { 55 | 56 | Optional orderTo = orderRepo.findById(orderId); 57 | Orders order = orderTo.get(); 58 | System.out.println("Quantity :" + order.getQuantity()); 59 | System.out.println("Price :" + order.getPrice()); 60 | 61 | double x = (float) (order.getQuantity() * order.getPrice()); 62 | 63 | return x; 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package org.product.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.product.dto.ProductRequest; 6 | import org.product.dto.ProductResponse; 7 | import org.product.services.ProductService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.DeleteMapping; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.PutMapping; 14 | import org.springframework.web.bind.annotation.RequestBody; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | @RestController 18 | public class ProductController { 19 | 20 | @Autowired 21 | ProductService service; 22 | 23 | @PostMapping(path = "/api/v1/product", consumes = { "application/json", "application/xml" }, produces = { 24 | "application/json", "application/xml" }) 25 | public ProductResponse addproductDetails(@RequestBody ProductRequest request) { 26 | return service.addProduct(request); 27 | } 28 | 29 | @PutMapping(path = "/api/v1/product/{productId}", consumes = { "application/json", "application/xml" }, produces = { 30 | "application/json", "application/xml" }) 31 | public ProductResponse UpdateProduct(@PathVariable Long productId, @RequestBody ProductRequest request) { 32 | return service.UpdateProduct(productId, request); 33 | } 34 | 35 | @DeleteMapping(path = "/api/v1/product/{productId}", consumes = { "application/json", 36 | "application/xml" }, produces = { "application/json", "application/xml" }) 37 | public ProductResponse deleteProduct(@PathVariable Long productId) { 38 | return service.deleteProduct(productId); 39 | } 40 | 41 | @GetMapping(path = "/api/v1/product/{productId}", consumes = { "application/json", "application/xml" }, produces = { 42 | "application/json", "application/xml" }) 43 | public ProductResponse searchProduct(@PathVariable Long productId) { 44 | return service.getSingleProduct(productId); 45 | } 46 | @GetMapping(path = "/api/v1/product", consumes = { "application/json", "application/xml" }, produces = { 47 | "application/json", "application/xml" }) 48 | public List getAllProductId() { 49 | return service.getAllProductIds(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /authentication-service/src/main/java/org/users/services/UserManagementService.java: -------------------------------------------------------------------------------- 1 | package org.users.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.users.dto.UserData; 9 | import org.users.dto.UserRequest; 10 | import org.users.dto.UserResponse; 11 | import org.users.entity.Users; 12 | import org.users.repo.UsersRepository; 13 | 14 | @Service 15 | public class UserManagementService { 16 | 17 | @Autowired 18 | UsersRepository userRepo; 19 | 20 | public UserResponse adduser(UserRequest userRequest) { 21 | 22 | UserResponse response = new UserResponse(); 23 | response.setUserData(new UserData()); 24 | Users usersTable = new Users(); 25 | 26 | usersTable.setAge(userRequest.getAge()); 27 | usersTable.setEmail(userRequest.getEmail()); 28 | usersTable.setPassword(userRequest.getPassword()); 29 | usersTable.setUserName(userRequest.getUsername()); 30 | 31 | userRepo.save(usersTable); 32 | 33 | response.setStatus("Success"); 34 | response.setMessage("User successfully added"); 35 | response.setUserId(usersTable.getUserId()); 36 | response.getUserData().setAge(usersTable.getAge()); 37 | response.getUserData().setEmail(usersTable.getEmail()); 38 | response.getUserData().setPassword(usersTable.getPassword()); 39 | response.getUserData().setUsername(usersTable.getUserName()); 40 | 41 | return response; 42 | 43 | } 44 | 45 | public UserResponse getSingleUser(Long userId) { 46 | 47 | UserResponse userResponse = new UserResponse(); 48 | 49 | Optional receivedData = userRepo.findById(userId); 50 | 51 | if (receivedData.isEmpty()) { 52 | userResponse.setStatus("Fail"); 53 | userResponse.setMessage("User not Found"); 54 | } else { 55 | if (userResponse.getUserData() == null) { 56 | userResponse.setUserData(new UserData()); 57 | } 58 | Users user = receivedData.get(); 59 | userResponse.setStatus("success"); 60 | userResponse.setMessage("User Found"); 61 | userResponse.userData.setAge(user.getAge()); 62 | userResponse.userData.setEmail(user.getEmail()); 63 | userResponse.userData.setUsername(user.getUserName()); 64 | userResponse.userData.setPassword(user.getPassword()); 65 | userResponse.setUserId(user.getUserId()); 66 | } 67 | return userResponse; 68 | } 69 | 70 | public UserResponse deleteUser(Long userId) { 71 | UserResponse userResponse = new UserResponse(); 72 | 73 | Optional receivedData = userRepo.findById(userId); 74 | 75 | if (receivedData.isEmpty()) { 76 | userResponse.setStatus("Fail"); 77 | userResponse.setMessage("User not Found"); 78 | } else { 79 | Users user = receivedData.get(); 80 | if (userResponse.getUserData() == null) { 81 | userResponse.setUserData(new UserData()); 82 | } 83 | userRepo.deleteById(userId); 84 | 85 | userResponse.setStatus("Success"); 86 | userResponse.setMessage("User successfully deleted"); 87 | userResponse.setUserId(user.getUserId()); 88 | userResponse.userData.setAge(user.getAge()); 89 | userResponse.userData.setEmail(user.getEmail()); 90 | userResponse.userData.setUsername(user.getUserName()); 91 | userResponse.userData.setPassword(user.getPassword()); 92 | } 93 | return userResponse; 94 | } 95 | 96 | @Autowired 97 | List userIds; 98 | 99 | public List getAllUserIds() { 100 | List users = userRepo.findAll(); 101 | 102 | for (Users user : users) 103 | userIds.add(user.getUserId()); 104 | return userIds; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /product-service/src/main/java/org/product/services/ProductService.java: -------------------------------------------------------------------------------- 1 | package org.product.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.product.dto.ProductData; 7 | import org.product.dto.ProductRequest; 8 | import org.product.dto.ProductResponse; 9 | import org.product.entity.Products; 10 | import org.product.repo.ProductsRepository; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Service; 13 | 14 | @Service 15 | public class ProductService { 16 | 17 | @Autowired 18 | List productIds; 19 | @Autowired 20 | ProductsRepository repo; 21 | 22 | public ProductResponse addProduct(ProductRequest request) { 23 | ProductResponse response = new ProductResponse(); 24 | 25 | Products productTable = new Products(); 26 | 27 | productTable.setProductName(request.getProductName()); 28 | productTable.setPrice(request.getPrice()); 29 | productTable.setQuantity(request.getQuantity()); 30 | 31 | repo.save(productTable); 32 | 33 | response.setStatus("Success"); 34 | response.setMessage("Product added successfully!!"); 35 | response.setProductId(productTable.getProductId()); 36 | 37 | return response; 38 | 39 | } 40 | 41 | public ProductResponse UpdateProduct(Long productId, ProductRequest request) { 42 | 43 | ProductResponse response = new ProductResponse(); 44 | response.setProductData(new ProductData()); 45 | Optional receivedData = repo.findById(productId); 46 | if (receivedData.isPresent()) { 47 | 48 | Products productTable = receivedData.get(); 49 | 50 | productTable.setProductName(request.getProductName()); 51 | productTable.setPrice(request.getPrice()); 52 | productTable.setQuantity(request.getQuantity()); 53 | productTable = repo.saveAndFlush(productTable); 54 | 55 | response.setStatus("Updated"); 56 | response.setMessage("Product Updated"); 57 | 58 | response.setProductId(productTable.getProductId()); 59 | response.productData.setProductName(productTable.getProductName()); 60 | response.productData.setPrice(productTable.getPrice()); 61 | 62 | } else { 63 | response.setStatus("Error"); 64 | response.setMessage("Product not found"); 65 | } 66 | return response; 67 | } 68 | 69 | public ProductResponse deleteProduct(Long productId) { 70 | ProductResponse response = new ProductResponse(); 71 | 72 | Optional receivedProduct = repo.findById(productId); 73 | 74 | if (receivedProduct.isPresent()) { 75 | repo.deleteById(productId); 76 | response.setStatus("Success"); 77 | response.setMessage("Product deleted successfully"); 78 | } else { 79 | response.setStatus("Error"); 80 | response.setMessage("Product not found"); 81 | } 82 | 83 | return response; 84 | } 85 | 86 | public ProductResponse getSingleProduct(Long productId) { 87 | 88 | ProductResponse response = new ProductResponse(); 89 | response.setProductData(new ProductData()); 90 | Optional receivedData = repo.findById(productId); 91 | 92 | if (!receivedData.isEmpty()) { 93 | Products product = receivedData.get(); 94 | response.setStatus("Success"); 95 | response.setMessage("Product found"); 96 | response.setProductId(product.getProductId()); 97 | response.productData.setProductName(product.getProductName()); 98 | response.productData.setPrice(product.getPrice()); 99 | response.productData.setQuantity(product.getQuantity()); 100 | } else { 101 | response.setStatus("Error"); 102 | response.setMessage("Product not found"); 103 | } 104 | 105 | return response; 106 | } 107 | 108 | public List getAllProductIds() { 109 | List products = repo.findAll(); 110 | 111 | for (Products product : products) 112 | productIds.add(product.getProductId()); 113 | return productIds; 114 | } 115 | } 116 | --------------------------------------------------------------------------------