├── .gitignore
├── Api-gateway
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── targa
│ │ │ └── labs
│ │ │ └── dev
│ │ │ └── apigateway
│ │ │ ├── ApiGatewayApplication.java
│ │ │ └── GatewayApi.java
│ └── resources
│ │ └── bootstrap.yml
│ └── test
│ └── java
│ └── com
│ └── targa
│ └── labs
│ └── dev
│ └── apigateway
│ └── ApiGatewayApplicationTests.java
├── BookReactor
└── pom.xml
├── CustomerService
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── targa
│ │ │ └── labs
│ │ │ └── dev
│ │ │ └── myboutique
│ │ │ └── customerservice
│ │ │ ├── CustomerServiceApplication.java
│ │ │ ├── config
│ │ │ ├── LoggingConfiguration.java
│ │ │ └── ServiceConfiguration.java
│ │ │ ├── domain
│ │ │ ├── Cart.java
│ │ │ ├── Customer.java
│ │ │ └── enumeration
│ │ │ │ └── CartStatus.java
│ │ │ ├── repository
│ │ │ ├── CartRepository.java
│ │ │ └── CustomerRepository.java
│ │ │ ├── service
│ │ │ ├── CartService.java
│ │ │ ├── CustomerService.java
│ │ │ └── OrderServiceClient.java
│ │ │ └── web
│ │ │ ├── CartResource.java
│ │ │ └── CustomerResource.java
│ └── resources
│ │ └── bootstrap.yml
│ └── test
│ └── java
│ └── com
│ └── targa
│ └── labs
│ └── dev
│ └── myboutique
│ └── customerservice
│ └── CustomerServiceApplicationTests.java
├── EurekaServer
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── targa
│ │ │ └── labs
│ │ │ └── dev
│ │ │ └── myboutique
│ │ │ └── eureka
│ │ │ └── EurekaApplication.java
│ └── resources
│ │ └── bootstrap.yml
│ └── test
│ └── java
│ └── com
│ └── targa
│ └── labs
│ └── dev
│ └── myboutique
│ └── eureka
│ └── EurekaApplicationTests.java
├── HystrixDashboard
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── targa
│ │ │ └── labs
│ │ │ └── dev
│ │ │ └── hystrixdashboard
│ │ │ └── HystrixDashboardApplication.java
│ └── resources
│ │ └── bootstrap.yml
│ └── test
│ └── java
│ └── com
│ └── targa
│ └── labs
│ └── dev
│ └── hystrixdashboard
│ └── HystrixDashboardApplicationTests.java
├── OrderService
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── targa
│ │ └── labs
│ │ └── dev
│ │ └── myboutique
│ │ └── orderservice
│ │ ├── DataLoader.java
│ │ ├── OrderServiceApplication.java
│ │ ├── config
│ │ ├── LoggingConfiguration.java
│ │ └── ServiceConfiguration.java
│ │ ├── domain
│ │ ├── Address.java
│ │ ├── Order.java
│ │ ├── OrderItem.java
│ │ ├── Payment.java
│ │ └── enumeration
│ │ │ ├── OrderStatus.java
│ │ │ └── PaymentStatus.java
│ │ ├── repository
│ │ ├── OrderItemRepository.java
│ │ ├── OrderRepository.java
│ │ └── PaymentRepository.java
│ │ ├── service
│ │ ├── AddressService.java
│ │ ├── OrderItemService.java
│ │ ├── OrderService.java
│ │ └── PaymentService.java
│ │ └── web
│ │ ├── OrderItemResource.java
│ │ ├── OrderResource.java
│ │ └── PaymentResource.java
│ └── resources
│ └── bootstrap.yml
├── ProductService
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── targa
│ │ └── labs
│ │ └── dev
│ │ └── myboutique
│ │ └── productservice
│ │ ├── ProductServiceApplication.java
│ │ ├── config
│ │ ├── LoggingConfiguration.java
│ │ └── ServiceConfiguration.java
│ │ ├── domain
│ │ ├── Category.java
│ │ ├── Product.java
│ │ ├── Review.java
│ │ └── enumeration
│ │ │ └── ProductStatus.java
│ │ ├── repository
│ │ ├── CategoryRepository.java
│ │ ├── ProductRepository.java
│ │ └── ReviewRepository.java
│ │ ├── service
│ │ ├── CategoryService.java
│ │ ├── ProductService.java
│ │ └── ReviewService.java
│ │ └── web
│ │ ├── CategoryResource.java
│ │ ├── ProductResource.java
│ │ ├── ReviewResource.java
│ │ └── ZipkinController2.java
│ └── resources
│ ├── bootstrap.yml
│ └── data.sql
├── myboutique-commons
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── targa
│ └── labs
│ └── dev
│ └── myboutique
│ └── commons
│ ├── domain
│ └── AbstractEntity.java
│ ├── dto
│ ├── AddressDto.java
│ ├── CartDto.java
│ ├── CategoryDto.java
│ ├── CustomerDto.java
│ ├── OrderDto.java
│ ├── OrderItemDto.java
│ ├── PaymentDto.java
│ ├── ProductDto.java
│ └── ReviewDto.java
│ └── utils
│ └── Web.java
└── myboutique-config-server
├── .gitignore
├── Dockerfile
├── nbactions.xml
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── targa
│ │ └── labs
│ │ └── dev
│ │ └── myboutique
│ │ └── configserver
│ │ └── ConfigserverApplication.java
└── resources
│ ├── application.yml
│ └── configurations
│ ├── application.yml
│ ├── customer-service.yml
│ ├── discovery-service.yml
│ ├── gateway-service.yml
│ ├── hystrix-dashboard.yml
│ ├── order-service.yml
│ └── product-service.yml
└── test
└── java
└── com
└── targa
└── labs
└── dev
└── myboutique
└── configserver
└── ConfigserverApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/java,maven,netbeans,intellij,java-web,code-java
3 |
4 | ### Code-Java ###
5 | # Language Support for Java(TM) by Red Hat extension for Visual Studio Code - https://marketplace.visualstudio.com/items?itemName=redhat.java
6 |
7 | .project
8 | .classpath
9 | factoryConfiguration.json
10 |
11 | ### Intellij ###
12 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
13 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
14 |
15 | # User-specific stuff
16 | .idea/**/workspace.xml
17 | .idea/**/tasks.xml
18 | .idea/**/usage.statistics.xml
19 | .idea/**/dictionaries
20 | .idea/**/shelf
21 |
22 | # Generated files
23 | .idea/**/contentModel.xml
24 |
25 | # Sensitive or high-churn files
26 | .idea/**/dataSources/
27 | .idea/**/dataSources.ids
28 | .idea/**/dataSources.local.xml
29 | .idea/**/sqlDataSources.xml
30 | .idea/**/dynamic.xml
31 | .idea/**/uiDesigner.xml
32 | .idea/**/dbnavigator.xml
33 |
34 | # Gradle
35 | .idea/**/gradle.xml
36 | .idea/**/libraries
37 |
38 | # Gradle and Maven with auto-import
39 | # When using Gradle or Maven with auto-import, you should exclude module files,
40 | # since they will be recreated, and may cause churn. Uncomment if using
41 | # auto-import.
42 | # .idea/modules.xml
43 | # .idea/*.iml
44 | # .idea/modules
45 |
46 | # CMake
47 | cmake-build-*/
48 |
49 | # Mongo Explorer plugin
50 | .idea/**/mongoSettings.xml
51 |
52 | # File-based project format
53 | *.iws
54 |
55 | # IntelliJ
56 | out/
57 |
58 | # mpeltonen/sbt-idea plugin
59 | .idea_modules/
60 |
61 | # JIRA plugin
62 | atlassian-ide-plugin.xml
63 |
64 | # Cursive Clojure plugin
65 | .idea/replstate.xml
66 |
67 | # Crashlytics plugin (for Android Studio and IntelliJ)
68 | com_crashlytics_export_strings.xml
69 | crashlytics.properties
70 | crashlytics-build.properties
71 | fabric.properties
72 |
73 | # Editor-based Rest Client
74 | .idea/httpRequests
75 |
76 | # Android studio 3.1+ serialized cache file
77 | .idea/caches/build_file_checksums.ser
78 |
79 | ### Intellij Patch ###
80 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
81 |
82 | # *.iml
83 | # modules.xml
84 | # .idea/misc.xml
85 | # *.ipr
86 |
87 | # Sonarlint plugin
88 | .idea/sonarlint
89 |
90 | ### Java ###
91 | # Compiled class file
92 | *.class
93 |
94 | # Log file
95 | *.log
96 |
97 | # BlueJ files
98 | *.ctxt
99 |
100 | # Mobile Tools for Java (J2ME)
101 | .mtj.tmp/
102 |
103 | # Package Files #
104 | *.jar
105 | *.war
106 | *.nar
107 | *.ear
108 | *.zip
109 | *.tar.gz
110 | *.rar
111 |
112 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
113 | hs_err_pid*
114 |
115 | ### Java-Web ###
116 | ## ignoring target file
117 | target/
118 |
119 | ### Maven ###
120 | pom.xml.tag
121 | pom.xml.releaseBackup
122 | pom.xml.versionsBackup
123 | pom.xml.next
124 | release.properties
125 | dependency-reduced-pom.xml
126 | buildNumber.properties
127 | .mvn/timing.properties
128 | .mvn/wrapper/maven-wrapper.jar
129 |
130 | ### NetBeans ###
131 | nbproject/private/
132 | build/
133 | nbbuild/
134 | dist/
135 | nbdist/
136 | .nb-gradle/
137 |
138 |
139 | # End of https://www.gitignore.io/api/java,maven,netbeans,intellij,java-web,code-java
140 |
--------------------------------------------------------------------------------
/Api-gateway/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/Api-gateway/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 8222
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/Api-gateway/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.apigateway.Api-gatewayApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.apigateway.Api-gatewayApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.apigateway.Api-gatewayApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/Api-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | api-gateway
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | api-gateway
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | 2.2.2.RELEASE
26 | Hoxton.SR1
27 | 4.3.1
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-dependencies
36 | ${spring-boot.version}
37 | pom
38 | import
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-dependencies
43 | ${spring-cloud.version}
44 | pom
45 | import
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-starter-actuator
54 |
55 |
56 | org.springframework.cloud
57 | spring-cloud-starter-gateway
58 |
59 |
60 | org.springframework.cloud
61 | spring-cloud-starter-netflix-zuul
62 |
63 |
64 | org.springframework.cloud
65 | spring-cloud-starter-netflix-ribbon
66 |
67 |
68 | io.springfox
69 | springfox-swagger-ui
70 | 2.9.2
71 |
72 |
73 | io.springfox
74 | springfox-swagger2
75 | 2.9.2
76 |
77 |
78 |
79 | org.springframework.boot
80 | spring-boot-starter-test
81 | test
82 |
83 |
84 |
85 |
86 |
87 |
88 | org.springframework.boot
89 | spring-boot-maven-plugin
90 |
91 |
92 |
93 |
94 |
95 |
96 | openshift
97 |
98 |
99 |
100 | io.fabric8
101 | fabric8-maven-plugin
102 | ${fabric8.version}
103 |
104 |
105 |
106 |
107 | ${project.name}
108 | LoadBalancer
109 |
110 |
111 |
112 |
113 |
114 |
115 | fmp
116 |
117 | resource
118 | build
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/Api-gateway/src/main/java/com/targa/labs/dev/apigateway/ApiGatewayApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.apigateway;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.SpringApplication;
7 | import org.springframework.boot.autoconfigure.SpringBootApplication;
8 | import org.springframework.cloud.client.discovery.DiscoveryClient;
9 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
10 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
11 | import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator;
12 | import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties;
13 | import org.springframework.context.annotation.Bean;
14 | import org.springframework.web.client.RestTemplate;
15 |
16 | @EnableDiscoveryClient
17 | @SpringBootApplication
18 | public class ApiGatewayApplication {
19 |
20 | private static final Log log = LogFactory.getLog(ApiGatewayApplication.class);
21 |
22 | @Autowired
23 | private DiscoveryClient discoveryClient;
24 |
25 | @Bean
26 | public DiscoveryClientRouteDefinitionLocator discoveryClientRouteLocator(DiscoveryClient discoveryClient,
27 | DiscoveryLocatorProperties properties) {
28 | return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties);
29 | }
30 |
31 | public static void main(String[] args) {
32 | SpringApplication.run(ApiGatewayApplication.class, args);
33 | }
34 |
35 | @LoadBalanced
36 | @Bean
37 | RestTemplate restTemplate() {
38 | return new RestTemplate();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Api-gateway/src/main/java/com/targa/labs/dev/apigateway/GatewayApi.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.apigateway;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Primary;
10 | import springfox.documentation.swagger.web.SwaggerResource;
11 | import springfox.documentation.swagger.web.SwaggerResourcesProvider;
12 |
13 | @Configuration
14 | public class GatewayApi {
15 |
16 | @Autowired
17 | ZuulProperties properties;
18 |
19 | @Primary
20 | @Bean
21 | public SwaggerResourcesProvider swaggerResourcesProvider() {
22 | return () -> {
23 | List resources = new ArrayList();
24 | properties.getRoutes().values().stream()
25 | .forEach(route -> resources.add(createResource(route.getId(), "2.0")));
26 | return resources;
27 | };
28 | }
29 |
30 | private SwaggerResource createResource(String location, String version) {
31 | SwaggerResource swaggerResource = new SwaggerResource();
32 | swaggerResource.setName(location);
33 | swaggerResource.setLocation("/" + location + "/v2/api-docs");
34 | swaggerResource.setSwaggerVersion(version);
35 | return swaggerResource;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/Api-gateway/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: gateway-service
4 | cloud:
5 | gateway:
6 | discovery:
7 | locator:
8 | enabled: true
9 | url-expression: "'http://'+serviceId"
10 | server:
11 | port: 8080
12 | logging:
13 | level:
14 | org.springframework.cloud.gateway: TRACE
15 | org.springframework.cloud.loadbalancer: TRACE
16 | management:
17 | endpoints:
18 | web:
19 | exposure:
20 | include: '*'
21 | zuul:
22 | routes:
23 | customer:
24 | path: /customer/**
25 | product:
26 | path: /product/**
27 | order:
28 | path: /order/**
--------------------------------------------------------------------------------
/Api-gateway/src/test/java/com/targa/labs/dev/apigateway/ApiGatewayApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.apigateway;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ApiGatewayApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/BookReactor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.targa.labs.dev
5 | BookReactor
6 | 1.0.0-SNAPSHOT
7 | pom
8 |
9 | ../Api-gateway
10 | ../CustomerService
11 | ../EurekaServer
12 | ../HystrixDashboard
13 | ../myboutique-commons
14 | ../myboutique-config-server
15 | ../OrderService
16 | ../ProductService
17 |
18 |
19 | UTF-8
20 |
21 |
--------------------------------------------------------------------------------
/CustomerService/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/CustomerService/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 9992
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/CustomerService/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.myboutique.customerservice.Customer-serviceApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.myboutique.customerservice.Customer-serviceApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.myboutique.customerservice.Customer-serviceApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/CustomerService/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | customer-service
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | customer-service
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | 2.2.2.RELEASE
26 | Hoxton.SR1
27 | 4.3.1
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-actuator
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-data-jpa
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-web
42 |
43 |
44 | org.springframework.cloud
45 | spring-cloud-starter-config
46 |
47 |
48 | org.springframework.cloud
49 | spring-cloud-starter-netflix-eureka-client
50 |
51 |
52 | org.springframework.cloud
53 | spring-cloud-starter-netflix-hystrix
54 |
55 |
56 | org.springframework.cloud
57 | spring-cloud-starter-openfeign
58 |
59 |
60 | org.springframework.cloud
61 | spring-cloud-starter-sleuth
62 |
63 |
64 | org.springframework.cloud
65 | spring-cloud-starter-zipkin
66 |
67 |
68 |
69 | com.targa.labs.dev
70 | myboutique-commons
71 | 1.0.0-SNAPSHOT
72 |
73 |
74 |
75 | io.springfox
76 | springfox-swagger-ui
77 | 2.9.2
78 |
79 |
80 | io.springfox
81 | springfox-swagger2
82 | 2.9.2
83 |
84 |
85 |
86 | net.logstash.logback
87 | logstash-logback-encoder
88 | 6.3
89 |
90 |
91 | ch.qos.logback
92 | logback-classic
93 |
94 |
95 | ch.qos.logback
96 | logback-core
97 |
98 |
99 |
100 | com.h2database
101 | h2
102 | runtime
103 |
104 |
105 | org.projectlombok
106 | lombok
107 | true
108 |
109 |
110 | org.springframework.boot
111 | spring-boot-starter-test
112 | test
113 |
114 |
115 |
116 |
117 |
118 |
119 | org.springframework.cloud
120 | spring-cloud-dependencies
121 | ${spring-cloud.version}
122 | pom
123 | import
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | org.springframework.boot
132 | spring-boot-maven-plugin
133 |
134 |
135 | com.spotify
136 | dockerfile-maven-plugin
137 | 1.4.13
138 |
139 | nebrass/${project.artifactId}
140 | ${project.version}
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/CustomerServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import org.springframework.cloud.openfeign.EnableFeignClients;
7 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
8 |
9 | @EnableSwagger2
10 | @EnableFeignClients
11 | @EnableCircuitBreaker
12 | @SpringBootApplication
13 | public class CustomerServiceApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(CustomerServiceApplication.class, args);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/config/LoggingConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.config;
2 |
3 | import java.net.InetSocketAddress;
4 |
5 | import ch.qos.logback.classic.AsyncAppender;
6 | import ch.qos.logback.classic.LoggerContext;
7 | import net.logstash.logback.appender.LogstashTcpSocketAppender;
8 | import net.logstash.logback.encoder.LogstashEncoder;
9 | import net.logstash.logback.stacktrace.ShortenedThrowableConverter;
10 | import org.slf4j.Logger;
11 | import org.slf4j.LoggerFactory;
12 | import org.springframework.beans.factory.annotation.Value;
13 | import org.springframework.context.annotation.Configuration;
14 |
15 | @Configuration
16 | public class LoggingConfiguration {
17 |
18 | private static final String LOGSTASH_APPENDER_NAME = "LOGSTASH";
19 | private static final String ASYNC_LOGSTASH_APPENDER_NAME = "ASYNC_LOGSTASH";
20 |
21 | private final Logger LOG = LoggerFactory.getLogger(LoggingConfiguration.class);
22 | private final LoggerContext CONTEXT = (LoggerContext) LoggerFactory.getILoggerFactory();
23 |
24 | private final String appName;
25 | private final String logstashHost;
26 | private final Integer logstashPort;
27 | private final Integer logstashQueueSize;
28 |
29 | public LoggingConfiguration(
30 | @Value("${spring.application.name}") String appName,
31 | @Value("${logstash.host}") String logstashHost,
32 | @Value("${logstash.port}") Integer logstashPort,
33 | @Value("${logstash.queue-size}") Integer logstashQueueSize) {
34 |
35 | this.appName = appName;
36 | this.logstashHost = logstashHost;
37 | this.logstashPort = logstashPort;
38 | this.logstashQueueSize = logstashQueueSize;
39 |
40 | addLogstashAppender(CONTEXT);
41 |
42 | }
43 |
44 | private void addLogstashAppender(LoggerContext context) {
45 | LOG.info("Initializing Logstash logging");
46 |
47 | LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
48 | logstashAppender.setName(LOGSTASH_APPENDER_NAME);
49 | logstashAppender.setContext(context);
50 | String customFields = "{\"servicename\":\"" + this.appName + "\"}";
51 |
52 | // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
53 | LogstashEncoder logstashEncoder = new LogstashEncoder();
54 | // Set the Logstash appender config
55 | logstashEncoder.setCustomFields(customFields);
56 | // Set the Logstash appender config
57 | logstashAppender.addDestinations(
58 | new InetSocketAddress(this.logstashHost, this.logstashPort)
59 | );
60 |
61 | ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
62 | throwableConverter.setRootCauseFirst(true);
63 | logstashEncoder.setThrowableConverter(throwableConverter);
64 | logstashEncoder.setCustomFields(customFields);
65 |
66 | logstashAppender.setEncoder(logstashEncoder);
67 | logstashAppender.start();
68 |
69 | // Wrap the appender in an Async appender for performance
70 | AsyncAppender asyncLogstashAppender = new AsyncAppender();
71 | asyncLogstashAppender.setContext(context);
72 | asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
73 | asyncLogstashAppender.setQueueSize(this.logstashQueueSize);
74 | asyncLogstashAppender.addAppender(logstashAppender);
75 | asyncLogstashAppender.start();
76 |
77 | context.getLogger("ROOT").addAppender(asyncLogstashAppender);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/config/ServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.config;
2 |
3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.client.RestTemplate;
7 |
8 | /**
9 | *
10 | * @author n.lamouchi
11 | */
12 | @Configuration
13 | public class ServiceConfiguration {
14 |
15 | @Bean
16 | @LoadBalanced
17 | public RestTemplate restTemplate() {
18 | return new RestTemplate();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/domain/Cart.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.domain;
2 |
3 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
4 | import com.targa.labs.dev.myboutique.customerservice.domain.enumeration.CartStatus;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 |
9 | import javax.persistence.*;
10 | import javax.validation.constraints.NotNull;
11 |
12 | /**
13 | * A Cart.
14 | */
15 | @Data
16 | @AllArgsConstructor
17 | @EqualsAndHashCode(callSuper = false)
18 | @Entity
19 | @Table(name = "cart")
20 | public class Cart extends AbstractEntity {
21 |
22 | private static final long serialVersionUID = 1L;
23 |
24 | @Id
25 | @GeneratedValue(strategy = GenerationType.IDENTITY)
26 | private Long id;
27 |
28 | private Long orderId;
29 |
30 | @ManyToOne
31 | private Customer customer;
32 |
33 | @NotNull
34 | @Enumerated(EnumType.STRING)
35 | private CartStatus status;
36 |
37 | public Cart(Customer customer) {
38 | this.customer = customer;
39 | this.status = CartStatus.NEW;
40 | }
41 |
42 | public Cart(Customer customer, CartStatus status) {
43 | this.customer = customer;
44 | this.status = status;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/domain/Customer.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 | import lombok.NoArgsConstructor;
9 |
10 | import javax.persistence.Column;
11 | import javax.persistence.Entity;
12 | import javax.persistence.OneToMany;
13 | import javax.persistence.Table;
14 | import javax.validation.constraints.Email;
15 | import java.util.Set;
16 | import javax.persistence.GeneratedValue;
17 | import javax.persistence.GenerationType;
18 | import javax.persistence.Id;
19 |
20 | /**
21 | * A Customer.
22 | */
23 | @Data
24 | @NoArgsConstructor
25 | @AllArgsConstructor
26 | @EqualsAndHashCode(callSuper = false)
27 | @Entity
28 | @Table(name = "customer")
29 | public class Customer extends AbstractEntity {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | @Id
34 | @GeneratedValue(strategy = GenerationType.IDENTITY)
35 | private Long id;
36 |
37 | @Column(name = "first_name")
38 | private String firstName;
39 |
40 | @Column(name = "last_name")
41 | private String lastName;
42 |
43 | @Email
44 | @Column(name = "email")
45 | private String email;
46 |
47 | @Column(name = "telephone")
48 | private String telephone;
49 |
50 | @OneToMany(mappedBy = "customer")
51 | @JsonIgnore
52 | private Set carts;
53 |
54 | @Column(name = "enabled", nullable = false)
55 | private Boolean enabled;
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/domain/enumeration/CartStatus.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.domain.enumeration;
2 |
3 | /**
4 | *
5 | * @author n.lamouchi
6 | */
7 | public enum CartStatus {
8 | NEW, CANCELED, CONFIRMED;
9 | }
10 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/repository/CartRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.customerservice.domain.Cart;
4 | import com.targa.labs.dev.myboutique.customerservice.domain.enumeration.CartStatus;
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 | import org.springframework.stereotype.Repository;
7 |
8 | import java.util.List;
9 |
10 | @Repository
11 | public interface CartRepository extends JpaRepository {
12 |
13 | List findByStatus(CartStatus status);
14 |
15 | List findByStatusAndCustomerId(CartStatus status, Long customerId);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/repository/CustomerRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.customerservice.domain.Customer;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface CustomerRepository extends JpaRepository {
11 |
12 | List findAllByEnabled(Boolean enabled);
13 | }
14 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/service/CartService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CartDto;
4 | import com.targa.labs.dev.myboutique.commons.dto.OrderDto;
5 | import com.targa.labs.dev.myboutique.customerservice.domain.Cart;
6 | import com.targa.labs.dev.myboutique.customerservice.domain.Customer;
7 | import com.targa.labs.dev.myboutique.customerservice.domain.enumeration.CartStatus;
8 | import com.targa.labs.dev.myboutique.customerservice.repository.CartRepository;
9 | import com.targa.labs.dev.myboutique.customerservice.repository.CustomerRepository;
10 | import lombok.RequiredArgsConstructor;
11 | import lombok.extern.slf4j.Slf4j;
12 | import org.springframework.stereotype.Service;
13 | import org.springframework.transaction.annotation.Transactional;
14 |
15 | import java.util.List;
16 | import java.util.stream.Collectors;
17 |
18 | @RequiredArgsConstructor
19 | @Slf4j
20 | @Service
21 | @Transactional
22 | public class CartService {
23 |
24 | private final CartRepository cartRepository;
25 | private final CustomerRepository customerRepository;
26 | private final OrderServiceClient orderService;
27 |
28 | public List findAll() {
29 | log.debug("Request to get all Carts");
30 | return this.cartRepository.findAll()
31 | .stream()
32 | .map(CartService::mapToDto)
33 | .collect(Collectors.toList());
34 | }
35 |
36 | public List findAllActiveCarts() {
37 | return this.cartRepository.findByStatus(CartStatus.NEW)
38 | .stream()
39 | .map(CartService::mapToDto)
40 | .collect(Collectors.toList());
41 | }
42 |
43 | public CartDto create(Long customerId) {
44 | if (this.getActiveCart(customerId) == null) {
45 | Customer customer = this.customerRepository.findById(customerId)
46 | .orElseThrow(() -> new IllegalStateException("The Customer does not exist!"));
47 |
48 | Cart cart = new Cart(
49 | customer,
50 | CartStatus.NEW
51 | );
52 |
53 | OrderDto order = this.orderService.create(mapToDto(cart));
54 | cart.setOrderId(order.getId());
55 |
56 | return mapToDto(this.cartRepository.save(cart));
57 | } else {
58 | throw new IllegalStateException("There is already an active cart");
59 | }
60 | }
61 |
62 | @Transactional(readOnly = true)
63 | public CartDto findById(Long id) {
64 | log.debug("Request to get Cart : {}", id);
65 | return this.cartRepository.findById(id).map(CartService::mapToDto).orElse(null);
66 | }
67 |
68 | public void delete(Long id) {
69 | log.debug("Request to delete Cart : {}", id);
70 | Cart cart = this.cartRepository.findById(id)
71 | .orElseThrow(() -> new IllegalStateException("Cannot find cart with id " + id));
72 |
73 | cart.setStatus(CartStatus.CANCELED);
74 |
75 | this.cartRepository.save(cart);
76 | }
77 |
78 | public CartDto getActiveCart(Long customerId) {
79 | List carts = this.cartRepository
80 | .findByStatusAndCustomerId(CartStatus.NEW, customerId);
81 | if (carts != null) {
82 |
83 | if (carts.size() == 1) {
84 | return mapToDto(carts.get(0));
85 | }
86 | if (carts.size() > 1) {
87 | throw new IllegalStateException("Many active carts detected !!!");
88 | }
89 | }
90 |
91 | return null;
92 | }
93 |
94 | public static CartDto mapToDto(Cart cart) {
95 | if (cart != null) {
96 | return new CartDto(
97 | cart.getId(),
98 | cart.getOrderId(),
99 | CustomerService.mapToDto(cart.getCustomer()),
100 | cart.getStatus().name()
101 | );
102 | }
103 | return null;
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/service/CustomerService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.customerservice.domain.Customer;
4 | import com.targa.labs.dev.myboutique.commons.dto.CustomerDto;
5 | import com.targa.labs.dev.myboutique.customerservice.repository.CustomerRepository;
6 | import lombok.RequiredArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | import java.util.Collections;
12 | import java.util.List;
13 | import java.util.stream.Collectors;
14 |
15 | @RequiredArgsConstructor
16 | @Slf4j
17 | @Service
18 | @Transactional
19 | public class CustomerService {
20 |
21 | private final CustomerRepository customerRepository;
22 |
23 | public CustomerDto create(CustomerDto customerDto) {
24 | log.debug("Request to create Customer : {}", customerDto);
25 | return mapToDto(
26 | this.customerRepository.save(
27 | new Customer(null,
28 | customerDto.getFirstName(),
29 | customerDto.getLastName(),
30 | customerDto.getEmail(),
31 | customerDto.getTelephone(),
32 | Collections.emptySet(),
33 | Boolean.TRUE
34 | )
35 | )
36 | );
37 | }
38 |
39 | public List findAll() {
40 | log.debug("Request to get all Customers");
41 | return this.customerRepository.findAll()
42 | .stream()
43 | .map(CustomerService::mapToDto)
44 | .collect(Collectors.toList());
45 | }
46 |
47 | @Transactional(readOnly = true)
48 | public CustomerDto findById(Long id) {
49 | log.debug("Request to get Customer : {}", id);
50 | return this.customerRepository.findById(id).map(CustomerService::mapToDto).orElse(null);
51 | }
52 |
53 | public List findAllActive() {
54 | log.debug("Request to get all Customers");
55 | return this.customerRepository.findAllByEnabled(true)
56 | .stream()
57 | .map(CustomerService::mapToDto)
58 | .collect(Collectors.toList());
59 | }
60 |
61 | public List findAllInactive() {
62 | log.debug("Request to get all Customers");
63 | return this.customerRepository.findAllByEnabled(false)
64 | .stream()
65 | .map(CustomerService::mapToDto)
66 | .collect(Collectors.toList());
67 | }
68 |
69 | public void delete(Long id) {
70 | log.debug("Request to delete Customer : {}", id);
71 |
72 | Customer customer = this.customerRepository.findById(id)
73 | .orElseThrow(() -> new IllegalStateException("Cannot find Customer with id " + id));
74 |
75 | customer.setEnabled(false);
76 | this.customerRepository.save(customer);
77 | }
78 |
79 | public static CustomerDto mapToDto(Customer customer) {
80 | if (customer != null) {
81 | return new CustomerDto(
82 | customer.getId(),
83 | customer.getFirstName(),
84 | customer.getLastName(),
85 | customer.getEmail(),
86 | customer.getTelephone()
87 | );
88 | }
89 | return null;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/service/OrderServiceClient.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CartDto;
4 | import com.targa.labs.dev.myboutique.commons.dto.OrderDto;
5 | import org.springframework.cloud.openfeign.FeignClient;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import static org.springframework.web.bind.annotation.RequestMethod.POST;
8 |
9 | /**
10 | *
11 | * @author n.lamouchi
12 | */
13 | @FeignClient(name = "order-service")
14 | public interface OrderServiceClient {
15 |
16 | @RequestMapping(value = "/api/orders", method = POST)
17 | OrderDto create(CartDto cartDto);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/web/CartResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.customerservice.web;
7 |
8 | import com.targa.labs.dev.myboutique.commons.dto.CartDto;
9 | import com.targa.labs.dev.myboutique.customerservice.service.CartService;
10 | import lombok.RequiredArgsConstructor;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.util.List;
14 |
15 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
16 |
17 | /**
18 | * @author n.lamouchi
19 | */
20 | @RequiredArgsConstructor
21 | @RestController
22 | @RequestMapping(API + "/carts")
23 | public class CartResource {
24 |
25 | private final CartService cartService;
26 |
27 | @GetMapping
28 | public List findAll() {
29 | return this.cartService.findAll();
30 | }
31 |
32 | @GetMapping("/active")
33 | public List findAllActiveCarts() {
34 | return this.cartService.findAllActiveCarts();
35 | }
36 |
37 | @GetMapping("/customer/{id}")
38 | public CartDto getActiveCartForCustomer(@PathVariable("id") Long customerId) {
39 | return this.cartService.getActiveCart(customerId);
40 | }
41 |
42 | @GetMapping("/{id}")
43 | public CartDto findById(@PathVariable Long id) {
44 | return this.cartService.findById(id);
45 | }
46 |
47 | @PostMapping("/customer/{id}")
48 | public CartDto create(@PathVariable("id") Long customerId) {
49 | return this.cartService.create(customerId);
50 | }
51 |
52 | @DeleteMapping("/{id}")
53 | public void delete(@PathVariable Long id) {
54 | this.cartService.delete(id);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/CustomerService/src/main/java/com/targa/labs/dev/myboutique/customerservice/web/CustomerResource.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice.web;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CustomerDto;
4 | import com.targa.labs.dev.myboutique.customerservice.service.CustomerService;
5 | import lombok.RequiredArgsConstructor;
6 | import org.springframework.web.bind.annotation.*;
7 |
8 | import java.util.List;
9 |
10 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @RequiredArgsConstructor
16 | @RestController
17 | @RequestMapping(API + "/customers")
18 | public class CustomerResource {
19 |
20 | private final CustomerService customerService;
21 |
22 | @GetMapping
23 | public List findAll() {
24 | return this.customerService.findAll();
25 | }
26 |
27 | @GetMapping("/{id}")
28 | public CustomerDto findById(@PathVariable Long id) {
29 | return this.customerService.findById(id);
30 | }
31 |
32 | @GetMapping("/active")
33 | public List findAllActive() {
34 | return this.customerService.findAllActive();
35 | }
36 |
37 | @GetMapping("/inactive")
38 | public List findAllInactive() {
39 | return this.customerService.findAllInactive();
40 | }
41 |
42 | @PostMapping
43 | public CustomerDto create(CustomerDto customerDto) {
44 | return this.customerService.create(customerDto);
45 | }
46 |
47 | @DeleteMapping("/{id}")
48 | public void delete(@PathVariable Long id) {
49 | this.customerService.delete(id);
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/CustomerService/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: customer-service
--------------------------------------------------------------------------------
/CustomerService/src/test/java/com/targa/labs/dev/myboutique/customerservice/CustomerServiceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.customerservice;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class CustomerServiceApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/EurekaServer/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/EurekaServer/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 8761
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/EurekaServer/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.myboutique.eureka.EurekaApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.myboutique.eureka.EurekaApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.myboutique.eureka.EurekaApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/EurekaServer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | eureka
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | eureka
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Hoxton.SR1
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-actuator
32 |
33 |
34 | org.springframework.cloud
35 | spring-cloud-starter-config
36 |
37 |
38 | org.springframework.cloud
39 | spring-cloud-starter-netflix-eureka-server
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.springframework.cloud
53 | spring-cloud-dependencies
54 | ${spring-cloud.version}
55 | pom
56 | import
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | org.springframework.boot
65 | spring-boot-maven-plugin
66 |
67 |
68 | com.spotify
69 | dockerfile-maven-plugin
70 | 1.4.13
71 |
72 | nebrass/${project.artifactId}
73 | ${project.version}
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/EurekaServer/src/main/java/com/targa/labs/dev/myboutique/eureka/EurekaApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.eureka;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | @EnableEurekaServer
8 | @SpringBootApplication
9 | public class EurekaApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(EurekaApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/EurekaServer/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | uri: http://localhost:8888
5 | application:
6 | name: discovery-service
--------------------------------------------------------------------------------
/EurekaServer/src/test/java/com/targa/labs/dev/myboutique/eureka/EurekaApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.eureka;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class EurekaApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/HystrixDashboard/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/HystrixDashboard/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 8988
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/HystrixDashboard/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.hystrixdashboard.Hystrix-dashboardApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.hystrixdashboard.Hystrix-dashboardApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.hystrixdashboard.Hystrix-dashboardApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/HystrixDashboard/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev
7 | hystrix-dashboard
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | hystrix-dashboard
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Hoxton.SR1
26 |
27 |
28 |
29 |
30 | org.springframework.cloud
31 | spring-cloud-starter-netflix-eureka-client
32 |
33 |
34 |
35 | org.springframework.cloud
36 | spring-cloud-starter-config
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-netflix-hystrix-dashboard
41 |
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-test
46 | test
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.springframework.cloud
54 | spring-cloud-dependencies
55 | ${spring-cloud.version}
56 | pom
57 | import
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | org.springframework.boot
66 | spring-boot-maven-plugin
67 |
68 |
69 | com.spotify
70 | dockerfile-maven-plugin
71 | 1.4.13
72 |
73 | nebrass/${project.artifactId}
74 | ${project.version}
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/HystrixDashboard/src/main/java/com/targa/labs/dev/hystrixdashboard/HystrixDashboardApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.hystrixdashboard;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
6 |
7 | @EnableHystrixDashboard
8 | @SpringBootApplication
9 | public class HystrixDashboardApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(HystrixDashboardApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/HystrixDashboard/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | uri: http://localhost:8888
5 | application:
6 | name: hystrix-dashboard
--------------------------------------------------------------------------------
/HystrixDashboard/src/test/java/com/targa/labs/dev/hystrixdashboard/HystrixDashboardApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.hystrixdashboard;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class HystrixDashboardApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/OrderService/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/OrderService/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 9991
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/OrderService/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.myboutique.orderservice.Order-serviceApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.myboutique.orderservice.Order-serviceApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.myboutique.orderservice.Order-serviceApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/OrderService/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | order-service
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | order-service
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Hoxton.SR1
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-actuator
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-data-jpa
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-web
40 |
41 |
42 | org.springframework.cloud
43 | spring-cloud-starter-config
44 |
45 |
46 | org.springframework.cloud
47 | spring-cloud-starter-netflix-eureka-client
48 |
49 |
50 | org.springframework.cloud
51 | spring-cloud-starter-netflix-hystrix
52 |
53 |
54 | org.springframework.cloud
55 | spring-cloud-starter-netflix-ribbon
56 |
57 |
58 | org.springframework.cloud
59 | spring-cloud-starter-openfeign
60 |
61 |
62 | org.springframework.cloud
63 | spring-cloud-starter-sleuth
64 |
65 |
66 | org.springframework.cloud
67 | spring-cloud-starter-zipkin
68 |
69 |
70 |
71 | io.springfox
72 | springfox-swagger-ui
73 | 2.9.2
74 |
75 |
76 | io.springfox
77 | springfox-swagger2
78 | 2.9.2
79 |
80 |
81 |
82 | net.logstash.logback
83 | logstash-logback-encoder
84 | 6.3
85 |
86 |
87 | ch.qos.logback
88 | logback-classic
89 |
90 |
91 | ch.qos.logback
92 | logback-core
93 |
94 |
95 |
96 | com.targa.labs.dev
97 | myboutique-commons
98 | 1.0.0-SNAPSHOT
99 |
100 |
101 |
102 | com.h2database
103 | h2
104 | runtime
105 |
106 |
107 | org.projectlombok
108 | lombok
109 | true
110 |
111 |
112 |
113 | org.springframework.boot
114 | spring-boot-starter-test
115 | test
116 |
117 |
118 |
119 |
120 |
121 |
122 | org.springframework.cloud
123 | spring-cloud-dependencies
124 | ${spring-cloud.version}
125 | pom
126 | import
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | org.springframework.boot
135 | spring-boot-maven-plugin
136 |
137 |
138 | com.spotify
139 | dockerfile-maven-plugin
140 | 1.4.13
141 |
142 | nebrass/${project.artifactId}
143 | ${project.version}
144 |
145 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/DataLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.orderservice;
7 |
8 | import com.targa.labs.dev.myboutique.commons.dto.ProductDto;
9 | import lombok.extern.slf4j.Slf4j;
10 | import org.springframework.boot.CommandLineRunner;
11 | import org.springframework.http.ResponseEntity;
12 | import org.springframework.stereotype.Component;
13 | import org.springframework.web.client.RestTemplate;
14 |
15 | /**
16 | *
17 | * @author n.lamouchi
18 | */
19 | @Slf4j
20 | @Component
21 | public class DataLoader implements CommandLineRunner {
22 |
23 | private final RestTemplate restTemplate;
24 |
25 | public DataLoader(RestTemplate restTemplate) {
26 | this.restTemplate = restTemplate;
27 | }
28 |
29 | @Override
30 | public void run(String... strings) throws Exception {
31 | ResponseEntity productResponseEntity
32 | = this.restTemplate.getForEntity(
33 | "http://product-service/api/products/{id}",
34 | ProductDto.class,
35 | 6
36 | );
37 |
38 | log.error("############ " + productResponseEntity.getBody().toString() + " ###############");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/OrderServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
7 |
8 | @EnableSwagger2
9 | @EnableCircuitBreaker
10 | @SpringBootApplication
11 | public class OrderServiceApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(OrderServiceApplication.class, args);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/config/LoggingConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.config;
2 |
3 | import java.net.InetSocketAddress;
4 |
5 | import ch.qos.logback.classic.AsyncAppender;
6 | import ch.qos.logback.classic.LoggerContext;
7 | import net.logstash.logback.appender.LogstashTcpSocketAppender;
8 | import net.logstash.logback.encoder.LogstashEncoder;
9 | import net.logstash.logback.stacktrace.ShortenedThrowableConverter;
10 | import org.slf4j.Logger;
11 | import org.slf4j.LoggerFactory;
12 | import org.springframework.beans.factory.annotation.Value;
13 | import org.springframework.context.annotation.Configuration;
14 |
15 | @Configuration
16 | public class LoggingConfiguration {
17 |
18 | private static final String LOGSTASH_APPENDER_NAME = "LOGSTASH";
19 | private static final String ASYNC_LOGSTASH_APPENDER_NAME = "ASYNC_LOGSTASH";
20 |
21 | private final Logger LOG = LoggerFactory.getLogger(LoggingConfiguration.class);
22 | private final LoggerContext CONTEXT = (LoggerContext) LoggerFactory.getILoggerFactory();
23 |
24 | private final String appName;
25 | private final String logstashHost;
26 | private final Integer logstashPort;
27 | private final Integer logstashQueueSize;
28 |
29 | public LoggingConfiguration(
30 | @Value("${spring.application.name}") String appName,
31 | @Value("${logstash.host}") String logstashHost,
32 | @Value("${logstash.port}") Integer logstashPort,
33 | @Value("${logstash.queue-size}") Integer logstashQueueSize) {
34 |
35 | this.appName = appName;
36 | this.logstashHost = logstashHost;
37 | this.logstashPort = logstashPort;
38 | this.logstashQueueSize = logstashQueueSize;
39 |
40 | addLogstashAppender(CONTEXT);
41 |
42 | }
43 |
44 | private void addLogstashAppender(LoggerContext context) {
45 | LOG.info("Initializing Logstash logging");
46 |
47 | LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
48 | logstashAppender.setName(LOGSTASH_APPENDER_NAME);
49 | logstashAppender.setContext(context);
50 | String customFields = "{\"servicename\":\"" + this.appName + "\"}";
51 |
52 | // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
53 | LogstashEncoder logstashEncoder = new LogstashEncoder();
54 | // Set the Logstash appender config
55 | logstashEncoder.setCustomFields(customFields);
56 | // Set the Logstash appender config
57 | logstashAppender.addDestinations(
58 | new InetSocketAddress(this.logstashHost, this.logstashPort)
59 | );
60 |
61 | ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
62 | throwableConverter.setRootCauseFirst(true);
63 | logstashEncoder.setThrowableConverter(throwableConverter);
64 | logstashEncoder.setCustomFields(customFields);
65 |
66 | logstashAppender.setEncoder(logstashEncoder);
67 | logstashAppender.start();
68 |
69 | // Wrap the appender in an Async appender for performance
70 | AsyncAppender asyncLogstashAppender = new AsyncAppender();
71 | asyncLogstashAppender.setContext(context);
72 | asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
73 | asyncLogstashAppender.setQueueSize(this.logstashQueueSize);
74 | asyncLogstashAppender.addAppender(logstashAppender);
75 | asyncLogstashAppender.start();
76 |
77 | context.getLogger("ROOT").addAppender(asyncLogstashAppender);
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/config/ServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.config;
2 |
3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.client.RestTemplate;
7 |
8 | /**
9 | *
10 | * @author n.lamouchi
11 | */
12 | @Configuration
13 | public class ServiceConfiguration {
14 |
15 | @Bean
16 | @LoadBalanced
17 | public RestTemplate restTemplate() {
18 | return new RestTemplate();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/Address.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain;
2 |
3 |
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 |
8 | import javax.persistence.Column;
9 | import javax.persistence.Embeddable;
10 | import javax.validation.constraints.Size;
11 | import java.io.Serializable;
12 |
13 | /**
14 | * A Address.
15 | */
16 | @Data
17 | @AllArgsConstructor
18 | @EqualsAndHashCode(callSuper = false)
19 | @Embeddable
20 | public class Address implements Serializable {
21 |
22 | @Column(name = "address_1")
23 | private String address1;
24 |
25 | @Column(name = "address_2")
26 | private String address2;
27 |
28 | @Column(name = "city")
29 | private String city;
30 |
31 | //@NotNull
32 | @Size(max = 10)
33 | @Column(name = "postcode", length = 10)//, nullable = false)
34 | private String postcode;
35 |
36 | //@NotNull
37 | @Size(max = 2)
38 | @Column(name = "country", length = 2)//, nullable = false)
39 | private String country;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/Order.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
5 | import com.targa.labs.dev.myboutique.orderservice.domain.enumeration.OrderStatus;
6 | import lombok.AllArgsConstructor;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 |
10 | import javax.persistence.*;
11 | import javax.validation.constraints.NotNull;
12 | import java.math.BigDecimal;
13 | import java.time.ZonedDateTime;
14 | import java.util.Set;
15 |
16 | /**
17 | * A Orders.
18 | */
19 | @Data
20 | @AllArgsConstructor
21 | @EqualsAndHashCode(callSuper = false)
22 | @Entity
23 | @Table(name = "orders")
24 | public class Order extends AbstractEntity {
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | @Id
29 | @GeneratedValue(strategy = GenerationType.IDENTITY)
30 | private Long id;
31 |
32 | @NotNull
33 | @Column(name = "total_price", precision = 10, scale = 2, nullable = false)
34 | private BigDecimal totalPrice;
35 |
36 | @NotNull
37 | @Enumerated(EnumType.STRING)
38 | @Column(name = "status", nullable = false)
39 | private OrderStatus status;
40 |
41 | @Column(name = "shipped")
42 | private ZonedDateTime shipped;
43 |
44 | @OneToOne
45 | @JoinColumn(unique = true)
46 | private Payment payment;
47 |
48 | @Embedded
49 | private Address shipmentAddress;
50 |
51 | @OneToMany(mappedBy = "order")
52 | @JsonIgnore
53 | private Set orderItems;
54 |
55 | private Long cartId;
56 |
57 | public Order() {
58 | // Empty Constructor for JPA
59 | }
60 |
61 | public Order(BigDecimal totalPrice, OrderStatus status,
62 | ZonedDateTime shipped, Payment payment,
63 | Address shipmentAddress, Set orderItems, Long cartId) {
64 | this.totalPrice = totalPrice;
65 | this.status = status;
66 | this.shipped = shipped;
67 | this.payment = payment;
68 | this.shipmentAddress = shipmentAddress;
69 | this.orderItems = orderItems;
70 | this.cartId = cartId;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/OrderItem.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain;
2 |
3 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 | import lombok.NoArgsConstructor;
8 |
9 | import javax.persistence.Column;
10 | import javax.persistence.Entity;
11 | import javax.persistence.GeneratedValue;
12 | import javax.persistence.GenerationType;
13 | import javax.persistence.Id;
14 | import javax.persistence.ManyToOne;
15 | import javax.persistence.Table;
16 | import javax.validation.constraints.NotNull;
17 |
18 | /**
19 | * A OrderItem.
20 | */
21 | @Data
22 | @AllArgsConstructor
23 | @EqualsAndHashCode(callSuper = false)
24 | @Entity
25 | @Table(name = "order_items")
26 | public class OrderItem extends AbstractEntity {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | @Id
31 | @GeneratedValue(strategy = GenerationType.IDENTITY)
32 | private Long id;
33 |
34 | @NotNull
35 | @Column(name = "quantity", nullable = false)
36 | private Long quantity;
37 |
38 | private Long productId;
39 |
40 | @ManyToOne
41 | private Order order;
42 |
43 | public OrderItem() {
44 | // Empty Constructor for JPA
45 | }
46 |
47 | public OrderItem(Long quantity, Long productId, Order order) {
48 | this.quantity = quantity;
49 | this.productId = productId;
50 | this.order = order;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/Payment.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain;
2 |
3 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
4 | import com.targa.labs.dev.myboutique.orderservice.domain.enumeration.PaymentStatus;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Data;
7 | import lombok.EqualsAndHashCode;
8 |
9 | import javax.persistence.*;
10 | import javax.validation.constraints.NotNull;
11 |
12 | /**
13 | * A Payment.
14 | */
15 | @Data
16 | @AllArgsConstructor
17 | @EqualsAndHashCode(callSuper = false)
18 | @Entity
19 | @Table(name = "payment")
20 | public class Payment extends AbstractEntity {
21 |
22 | private static final long serialVersionUID = 1L;
23 |
24 | @Id
25 | @GeneratedValue(strategy = GenerationType.IDENTITY)
26 | private Long id;
27 |
28 | @Column(name = "paypal_payment_id")
29 | private String paypalPaymentId;
30 |
31 | @NotNull
32 | @Enumerated(EnumType.STRING)
33 | @Column(name = "status", nullable = false)
34 | private PaymentStatus status;
35 |
36 | @OneToOne
37 | @JoinColumn(unique = true)
38 | private Order order;
39 |
40 | public Payment() {
41 | // Empty Constructor for JPA
42 | }
43 |
44 | public Payment(String paypalPaymentId, PaymentStatus status, Order order) {
45 | this.paypalPaymentId = paypalPaymentId;
46 | this.status = status;
47 | this.order = order;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/enumeration/OrderStatus.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain.enumeration;
2 |
3 | /**
4 | * The OrderStatus enumeration.
5 | */
6 | public enum OrderStatus {
7 | CREATION, NEW, HOLD, SHIPPED, DELIVERED, CLOSED
8 | }
9 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/domain/enumeration/PaymentStatus.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.domain.enumeration;
2 |
3 | /**
4 | * The PaymentStatus enumeration.
5 | */
6 | public enum PaymentStatus {
7 | ACCEPTED, PENDING, REFUSED, ERROR
8 | }
9 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/repository/OrderItemRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.orderservice.domain.OrderItem;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface OrderItemRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/repository/OrderRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.orderservice.domain.Order;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 |
8 | @Repository
9 | public interface OrderRepository extends JpaRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/repository/PaymentRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.orderservice.domain.Payment;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface PaymentRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/service/AddressService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.orderservice.domain.Address;
4 | import com.targa.labs.dev.myboutique.commons.dto.AddressDto;
5 |
6 |
7 | public class AddressService {
8 |
9 | public static AddressDto mapToDto(Address address) {
10 | if (address != null) {
11 | return new AddressDto(
12 | address.getAddress1(),
13 | address.getAddress2(),
14 | address.getCity(),
15 | address.getPostcode(),
16 | address.getCountry()
17 | );
18 | }
19 | return null;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/service/OrderItemService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.OrderItemDto;
4 | import com.targa.labs.dev.myboutique.commons.dto.ProductDto;
5 | import com.targa.labs.dev.myboutique.orderservice.domain.Order;
6 | import com.targa.labs.dev.myboutique.orderservice.domain.OrderItem;
7 | import com.targa.labs.dev.myboutique.orderservice.repository.OrderItemRepository;
8 | import com.targa.labs.dev.myboutique.orderservice.repository.OrderRepository;
9 | import lombok.RequiredArgsConstructor;
10 | import lombok.extern.slf4j.Slf4j;
11 | import org.springframework.stereotype.Service;
12 | import org.springframework.transaction.annotation.Transactional;
13 |
14 | import java.util.List;
15 | import java.util.stream.Collectors;
16 | import org.springframework.http.ResponseEntity;
17 | import org.springframework.web.client.RestTemplate;
18 |
19 | @RequiredArgsConstructor
20 | @Slf4j
21 | @Service
22 | @Transactional
23 | public class OrderItemService {
24 |
25 | private final OrderItemRepository orderItemRepository;
26 | private final OrderRepository orderRepository;
27 | private final RestTemplate restTemplate;
28 |
29 | public List findAll() {
30 | log.debug("Request to get all OrderItems");
31 | return this.orderItemRepository.findAll()
32 | .stream()
33 | .map(OrderItemService::mapToDto)
34 | .collect(Collectors.toList());
35 | }
36 |
37 | @Transactional(readOnly = true)
38 | public OrderItemDto findById(Long id) {
39 | log.debug("Request to get OrderItem : {}", id);
40 | return this.orderItemRepository
41 | .findById(id)
42 | .map(OrderItemService::mapToDto)
43 | .orElse(null);
44 | }
45 |
46 | public OrderItemDto create(OrderItemDto orderItemDto) {
47 | log.debug("Request to create OrderItem : {}", orderItemDto);
48 | Order order = this.orderRepository
49 | .findById(orderItemDto.getOrderId())
50 | .orElseThrow(
51 | () -> new IllegalStateException("The Order does not exist!")
52 | );
53 |
54 | ResponseEntity productResponseEntity
55 | = this.restTemplate.getForEntity(
56 | "http://product-service/api/products/{id}",
57 | ProductDto.class,
58 | orderItemDto.getProductId()
59 | );
60 |
61 | return mapToDto(
62 | this.orderItemRepository.save(
63 | new OrderItem(
64 | orderItemDto.getQuantity(),
65 | productResponseEntity.getBody().getId(),
66 | order
67 | )));
68 | }
69 |
70 | public void delete(Long id) {
71 | log.debug("Request to delete OrderItem : {}", id);
72 | this.orderItemRepository.deleteById(id);
73 | }
74 |
75 | public static OrderItemDto mapToDto(OrderItem orderItem) {
76 | if (orderItem != null) {
77 | return new OrderItemDto(
78 | orderItem.getId(),
79 | orderItem.getQuantity(),
80 | orderItem.getProductId(),
81 | orderItem.getOrder().getId()
82 | );
83 | }
84 | return null;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/service/OrderService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CartDto;
4 | import com.targa.labs.dev.myboutique.commons.dto.OrderDto;
5 | import com.targa.labs.dev.myboutique.orderservice.domain.Order;
6 | import com.targa.labs.dev.myboutique.orderservice.domain.enumeration.OrderStatus;
7 | import com.targa.labs.dev.myboutique.orderservice.repository.OrderRepository;
8 | import lombok.RequiredArgsConstructor;
9 | import lombok.extern.slf4j.Slf4j;
10 | import org.springframework.stereotype.Service;
11 | import org.springframework.transaction.annotation.Transactional;
12 |
13 | import java.math.BigDecimal;
14 | import java.util.Collections;
15 | import java.util.List;
16 | import java.util.stream.Collectors;
17 |
18 | @RequiredArgsConstructor
19 | @Slf4j
20 | @Service
21 | @Transactional
22 | public class OrderService {
23 |
24 | private final OrderRepository orderRepository;
25 |
26 | public List findAll() {
27 | log.debug("Request to get all Orders");
28 | return this.orderRepository.findAll()
29 | .stream()
30 | .map(OrderService::mapToDto)
31 | .collect(Collectors.toList());
32 | }
33 |
34 | @Transactional(readOnly = true)
35 | public OrderDto findById(Long id) {
36 | log.debug("Request to get Order : {}", id);
37 | return this.orderRepository.findById(id).map(OrderService::mapToDto).orElse(null);
38 | }
39 |
40 | /*
41 | public List findAllByUser(Long id) {
42 | return this.orderRepository.findByCartCustomer_Id(id)
43 | .stream()
44 | .map(OrderService::mapToDto)
45 | .collect(Collectors.toList());
46 | }
47 | */
48 |
49 | public OrderDto create(OrderDto orderDto) {
50 | log.debug("Request to create Order : {}", orderDto);
51 | return mapToDto(
52 | this.orderRepository.save(
53 | new Order(
54 | BigDecimal.ZERO,
55 | OrderStatus.CREATION,
56 | null,
57 | null,
58 | null,
59 | Collections.emptySet(),
60 | null
61 | )
62 | )
63 | );
64 | }
65 |
66 | public Order createOrder(CartDto cart) {
67 | log.debug("Request to create Order with a Cart : {}", cart);
68 | return this.orderRepository.save(
69 | new Order(
70 | BigDecimal.ZERO,
71 | OrderStatus.CREATION,
72 | null,
73 | null,
74 | null,
75 | Collections.emptySet(),
76 | cart.getId()
77 | )
78 | );
79 | }
80 |
81 | public OrderDto create(CartDto cart) {
82 | return mapToDto(this.createOrder(cart));
83 | }
84 |
85 | public void delete(Long id) {
86 | log.debug("Request to delete Order : {}", id);
87 | this.orderRepository.deleteById(id);
88 | }
89 |
90 | public static OrderDto mapToDto(Order order) {
91 | if (order != null) {
92 | return new OrderDto(
93 | order.getId(),
94 | order.getTotalPrice(),
95 | order.getStatus().name(),
96 | order.getShipped(),
97 | PaymentService.mapToDto(order.getPayment()),
98 | AddressService.mapToDto(order.getShipmentAddress()),
99 | order.getOrderItems().stream().map(OrderItemService::mapToDto).collect(Collectors.toSet())
100 | );
101 | }
102 | return null;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/service/PaymentService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.orderservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.orderservice.domain.Payment;
4 | import com.targa.labs.dev.myboutique.commons.dto.PaymentDto;
5 | import com.targa.labs.dev.myboutique.orderservice.domain.Order;
6 | import com.targa.labs.dev.myboutique.orderservice.domain.enumeration.PaymentStatus;
7 | import com.targa.labs.dev.myboutique.orderservice.repository.OrderRepository;
8 | import com.targa.labs.dev.myboutique.orderservice.repository.PaymentRepository;
9 | import lombok.RequiredArgsConstructor;
10 | import lombok.extern.slf4j.Slf4j;
11 | import org.springframework.stereotype.Service;
12 | import org.springframework.transaction.annotation.Transactional;
13 |
14 | import java.util.List;
15 | import java.util.stream.Collectors;
16 |
17 | @RequiredArgsConstructor
18 | @Slf4j
19 | @Service
20 | @Transactional
21 | public class PaymentService {
22 |
23 | private final PaymentRepository paymentRepository;
24 | private final OrderRepository orderRepository;
25 |
26 | public List findAll() {
27 | log.debug("Request to get all Payments");
28 | return this.paymentRepository.findAll()
29 | .stream()
30 | .map(PaymentService::mapToDto)
31 | .collect(Collectors.toList());
32 | }
33 |
34 | @Transactional(readOnly = true)
35 | public PaymentDto findById(Long id) {
36 | log.debug("Request to get Payment : {}", id);
37 | return this.paymentRepository.findById(id).map(PaymentService::mapToDto).orElse(null);
38 | }
39 |
40 | public PaymentDto create(PaymentDto paymentDto) {
41 | log.debug("Request to create Payment : {}", paymentDto);
42 |
43 | Order order = this.orderRepository.findById(paymentDto.getOrderId()).orElseThrow(() -> new IllegalStateException("The Order does not exist!"));
44 |
45 | return mapToDto(this.paymentRepository.save(
46 | new Payment(
47 | paymentDto.getPaypalPaymentId(),
48 | PaymentStatus.valueOf(paymentDto.getStatus()),
49 | order
50 | )
51 | ));
52 | }
53 |
54 | public void delete(Long id) {
55 | log.debug("Request to delete Payment : {}", id);
56 | this.paymentRepository.deleteById(id);
57 | }
58 |
59 | public static PaymentDto mapToDto(Payment payment) {
60 | if (payment != null) {
61 | return new PaymentDto(
62 | payment.getId(),
63 | payment.getPaypalPaymentId(),
64 | payment.getStatus().name(),
65 | payment.getOrder().getId()
66 | );
67 | }
68 | return null;
69 | }
70 | }
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/web/OrderItemResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.orderservice.web;
7 |
8 | import com.targa.labs.dev.myboutique.orderservice.service.OrderItemService;
9 | import com.targa.labs.dev.myboutique.commons.dto.OrderItemDto;
10 | import lombok.RequiredArgsConstructor;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.util.List;
14 |
15 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
16 |
17 | /**
18 | * @author n.lamouchi
19 | */
20 | @RequiredArgsConstructor
21 | @RestController
22 | @RequestMapping(API + "/order-items")
23 | public class OrderItemResource {
24 |
25 | private final OrderItemService itemService;
26 |
27 | @GetMapping
28 | public List findAll() {
29 | return this.itemService.findAll();
30 | }
31 |
32 | @GetMapping("/{id}")
33 | public OrderItemDto findById(@PathVariable Long id) {
34 | return this.itemService.findById(id);
35 | }
36 |
37 | @PostMapping
38 | public OrderItemDto create(@RequestBody OrderItemDto orderItemDto) {
39 | return this.itemService.create(orderItemDto);
40 | }
41 |
42 | @DeleteMapping("/{id}")
43 | public void delete(@PathVariable Long id) {
44 | this.itemService.delete(id);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/web/OrderResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.orderservice.web;
7 |
8 | import com.targa.labs.dev.myboutique.orderservice.service.OrderService;
9 | import com.targa.labs.dev.myboutique.commons.dto.OrderDto;
10 | import lombok.RequiredArgsConstructor;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.util.List;
14 |
15 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
16 |
17 | /**
18 | * @author n.lamouchi
19 | */
20 | @RequiredArgsConstructor
21 | @RestController
22 | @RequestMapping(API + "/orders")
23 | public class OrderResource {
24 |
25 | private final OrderService orderService;
26 |
27 | @GetMapping
28 | public List findAll() {
29 | return this.orderService.findAll();
30 | }
31 |
32 | /*@GetMapping("/customer/{id}")
33 | public List findAllByUser(@PathVariable Long id) {
34 | return this.orderService.findAllByUser(id);
35 | }*/
36 |
37 | @GetMapping("/{id}")
38 | public OrderDto findById(@PathVariable Long id) {
39 | return this.orderService.findById(id);
40 | }
41 |
42 | @DeleteMapping("/{id}")
43 | public void delete(@PathVariable Long id) {
44 | this.orderService.delete(id);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/OrderService/src/main/java/com/targa/labs/dev/myboutique/orderservice/web/PaymentResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.orderservice.web;
7 |
8 | import com.targa.labs.dev.myboutique.commons.dto.PaymentDto;
9 | import com.targa.labs.dev.myboutique.orderservice.service.PaymentService;
10 | import lombok.RequiredArgsConstructor;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.util.List;
14 |
15 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
16 |
17 | /**
18 | * @author n.lamouchi
19 | */
20 | @RequiredArgsConstructor
21 | @RestController
22 | @RequestMapping(API + "/payments")
23 | public class PaymentResource {
24 |
25 | private final PaymentService paymentService;
26 |
27 | @GetMapping
28 | public List findAll() {
29 | return this.paymentService.findAll();
30 | }
31 |
32 | @GetMapping("/{id}")
33 | public PaymentDto findById(@PathVariable Long id) {
34 | return this.paymentService.findById(id);
35 | }
36 |
37 | @PostMapping
38 | public PaymentDto create(@RequestBody PaymentDto orderItemDto) {
39 | return this.paymentService.create(orderItemDto);
40 | }
41 |
42 | @DeleteMapping("/{id}")
43 | public void delete(@PathVariable Long id) {
44 | this.paymentService.delete(id);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/OrderService/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | uri: http://localhost:8888
5 | application:
6 | name: order-service
--------------------------------------------------------------------------------
/ProductService/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/ProductService/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/*.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 9990
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/ProductService/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.myboutique.productservice.Product-serviceApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.myboutique.productservice.Product-serviceApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.myboutique.productservice.Product-serviceApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/ProductService/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | product-service
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | product-service
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Hoxton.SR1
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-actuator
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-data-jpa
40 |
41 |
42 | org.springframework.cloud
43 | spring-cloud-starter-config
44 |
45 |
46 | org.springframework.cloud
47 | spring-cloud-starter-netflix-eureka-client
48 |
49 |
50 | org.springframework.cloud
51 | spring-cloud-starter-netflix-hystrix
52 |
53 |
54 | org.springframework.cloud
55 | spring-cloud-starter-sleuth
56 |
57 |
58 | org.springframework.cloud
59 | spring-cloud-starter-zipkin
60 |
61 |
62 | com.h2database
63 | h2
64 | runtime
65 |
66 |
67 |
68 | io.springfox
69 | springfox-swagger-ui
70 | 2.9.2
71 |
72 |
73 | io.springfox
74 | springfox-swagger2
75 | 2.9.2
76 |
77 |
78 |
79 | net.logstash.logback
80 | logstash-logback-encoder
81 | 6.3
82 |
83 |
84 | ch.qos.logback
85 | logback-classic
86 |
87 |
88 | ch.qos.logback
89 | logback-core
90 |
91 |
92 |
93 | org.springframework.boot
94 | spring-boot-starter-test
95 | test
96 |
97 |
98 | org.projectlombok
99 | lombok
100 |
101 |
102 |
103 | com.targa.labs.dev
104 | myboutique-commons
105 | 1.0.0-SNAPSHOT
106 |
107 |
108 |
109 |
110 |
111 |
112 | org.springframework.cloud
113 | spring-cloud-dependencies
114 | ${spring-cloud.version}
115 | pom
116 | import
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 | org.springframework.boot
125 | spring-boot-maven-plugin
126 |
127 |
128 | com.spotify
129 | dockerfile-maven-plugin
130 | 1.4.13
131 |
132 | nebrass/${project.artifactId}
133 | ${project.version}
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/ProductServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
7 |
8 | @EnableSwagger2
9 | @EnableCircuitBreaker
10 | @SpringBootApplication
11 | public class ProductServiceApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(ProductServiceApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/config/LoggingConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.productservice.config;
7 |
8 | import java.net.InetSocketAddress;
9 |
10 | import ch.qos.logback.classic.AsyncAppender;
11 | import ch.qos.logback.classic.LoggerContext;
12 | import net.logstash.logback.appender.LogstashTcpSocketAppender;
13 | import net.logstash.logback.encoder.LogstashEncoder;
14 | import net.logstash.logback.stacktrace.ShortenedThrowableConverter;
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 | import org.springframework.beans.factory.annotation.Value;
18 | import org.springframework.context.annotation.Configuration;
19 |
20 | @Configuration
21 | public class LoggingConfiguration {
22 |
23 | private static final String LOGSTASH_APPENDER_NAME = "LOGSTASH";
24 | private static final String ASYNC_LOGSTASH_APPENDER_NAME = "ASYNC_LOGSTASH";
25 |
26 | private final Logger LOG = LoggerFactory.getLogger(LoggingConfiguration.class);
27 | private final LoggerContext CONTEXT = (LoggerContext) LoggerFactory.getILoggerFactory();
28 |
29 | private final String appName;
30 | private final String logstashHost;
31 | private final Integer logstashPort;
32 | private final Integer logstashQueueSize;
33 |
34 | public LoggingConfiguration(
35 | @Value("${spring.application.name}") String appName,
36 | @Value("${logstash.host}") String logstashHost,
37 | @Value("${logstash.port}") Integer logstashPort,
38 | @Value("${logstash.queue-size}") Integer logstashQueueSize) {
39 |
40 | this.appName = appName;
41 | this.logstashHost = logstashHost;
42 | this.logstashPort = logstashPort;
43 | this.logstashQueueSize = logstashQueueSize;
44 |
45 | addLogstashAppender(CONTEXT);
46 |
47 | }
48 |
49 | private void addLogstashAppender(LoggerContext context) {
50 | LOG.info("Initializing Logstash logging");
51 |
52 | LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
53 | logstashAppender.setName(LOGSTASH_APPENDER_NAME);
54 | logstashAppender.setContext(context);
55 | String customFields = "{\"servicename\":\"" + this.appName + "\"}";
56 |
57 | // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
58 | LogstashEncoder logstashEncoder = new LogstashEncoder();
59 | // Set the Logstash appender config
60 | logstashEncoder.setCustomFields(customFields);
61 | // Set the Logstash appender config
62 | logstashAppender.addDestinations(
63 | new InetSocketAddress(this.logstashHost, this.logstashPort)
64 | );
65 |
66 | ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
67 | throwableConverter.setRootCauseFirst(true);
68 | logstashEncoder.setThrowableConverter(throwableConverter);
69 | logstashEncoder.setCustomFields(customFields);
70 |
71 | logstashAppender.setEncoder(logstashEncoder);
72 | logstashAppender.start();
73 |
74 | // Wrap the appender in an Async appender for performance
75 | AsyncAppender asyncLogstashAppender = new AsyncAppender();
76 | asyncLogstashAppender.setContext(context);
77 | asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
78 | asyncLogstashAppender.setQueueSize(this.logstashQueueSize);
79 | asyncLogstashAppender.addAppender(logstashAppender);
80 | asyncLogstashAppender.start();
81 |
82 | context.getLogger("ROOT").addAppender(asyncLogstashAppender);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/config/ServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.config;
2 |
3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.client.RestTemplate;
7 |
8 | /**
9 | *
10 | * @author n.lamouchi
11 | */
12 | @Configuration
13 | public class ServiceConfiguration {
14 |
15 | @Bean
16 | @LoadBalanced
17 | public RestTemplate restTemplate() {
18 | return new RestTemplate();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/domain/Category.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.domain;
2 |
3 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 | import lombok.NoArgsConstructor;
8 |
9 | import javax.persistence.*;
10 | import javax.validation.constraints.NotNull;
11 |
12 | /**
13 | * A Category.
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | @EqualsAndHashCode(callSuper = false)
19 | @Entity
20 | @Table(name = "category")
21 | public class Category extends AbstractEntity {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | @Id
26 | @GeneratedValue(strategy = GenerationType.AUTO)
27 | private Long id;
28 |
29 | @NotNull
30 | @Column(name = "name", nullable = false)
31 | private String name;
32 |
33 | @NotNull
34 | @Column(name = "description", nullable = false)
35 | private String description;
36 |
37 | public Category(String name, String description) {
38 | this.name = name;
39 | this.description = description;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/domain/Product.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
5 | import com.targa.labs.dev.myboutique.productservice.domain.enumeration.ProductStatus;
6 | import lombok.AllArgsConstructor;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.NoArgsConstructor;
10 |
11 | import javax.persistence.*;
12 | import javax.validation.constraints.NotNull;
13 | import java.math.BigDecimal;
14 | import java.util.HashSet;
15 | import java.util.Set;
16 |
17 | /**
18 | * A Product.
19 | */
20 | @Data
21 | @NoArgsConstructor
22 | @AllArgsConstructor
23 | @EqualsAndHashCode(callSuper = false)
24 | @Entity
25 | @Table(name = "product")
26 | public class Product extends AbstractEntity {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | @Id
31 | @GeneratedValue(strategy = GenerationType.AUTO)
32 | private Long id;
33 |
34 | @NotNull
35 | @Column(name = "name", nullable = false)
36 | private String name;
37 |
38 | @NotNull
39 | @Column(name = "description", nullable = false)
40 | private String description;
41 |
42 | @NotNull
43 | @Column(name = "price", precision = 10, scale = 2, nullable = false)
44 | private BigDecimal price;
45 |
46 | @Column(name = "quantity")
47 | private Integer quantity;
48 |
49 | @NotNull
50 | @Enumerated(EnumType.STRING)
51 | @Column(name = "status", nullable = false)
52 | private ProductStatus status;
53 |
54 | @Column(name = "sales_counter")
55 | private Integer salesCounter;
56 |
57 | @OneToMany
58 | @JsonIgnore
59 | private Set reviews = new HashSet<>();
60 |
61 | @ManyToOne
62 | private Category category;
63 |
64 | public Product(String name, String description, BigDecimal price,
65 | Integer quantity, ProductStatus status,
66 | Integer salesCounter, Category category) {
67 | this.name = name;
68 | this.description = description;
69 | this.price = price;
70 | this.quantity = quantity;
71 | this.status = status;
72 | this.salesCounter = salesCounter;
73 | this.category = category;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/domain/Review.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.domain;
2 |
3 | import com.targa.labs.dev.myboutique.commons.domain.AbstractEntity;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 | import lombok.NoArgsConstructor;
8 |
9 | import javax.persistence.*;
10 | import javax.validation.constraints.NotNull;
11 |
12 | /**
13 | * A Review.
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | @EqualsAndHashCode(callSuper = false)
19 | @Entity
20 | @Table(name = "review")
21 | public class Review extends AbstractEntity {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | @Id
26 | @GeneratedValue(strategy = GenerationType.AUTO)
27 | private Long id;
28 |
29 | @NotNull
30 | @Column(name = "text", nullable = false)
31 | private String title;
32 |
33 | @NotNull
34 | @Column(name = "description", nullable = false)
35 | private String description;
36 |
37 | @NotNull
38 | @Column(name = "rating", nullable = false)
39 | private Long rating;
40 |
41 | public Review(String title, String description, Long rating) {
42 | this.title = title;
43 | this.description = description;
44 | this.rating = rating;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/domain/enumeration/ProductStatus.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.domain.enumeration;
2 |
3 | /**
4 | * The ProductStatus enumeration.
5 | */
6 | public enum ProductStatus {
7 | AVAILABLE, DISCONTINUED
8 | }
9 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/repository/CategoryRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.productservice.domain.Category;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface CategoryRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/repository/ProductRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.productservice.domain.Product;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface ProductRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/repository/ReviewRepository.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.repository;
2 |
3 | import com.targa.labs.dev.myboutique.productservice.domain.Review;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface ReviewRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/service/CategoryService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CategoryDto;
4 | import com.targa.labs.dev.myboutique.productservice.domain.Category;
5 | import com.targa.labs.dev.myboutique.productservice.repository.CategoryRepository;
6 | import lombok.RequiredArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | import java.util.List;
12 | import java.util.stream.Collectors;
13 |
14 | @RequiredArgsConstructor
15 | @Slf4j
16 | @Service
17 | @Transactional
18 | public class CategoryService {
19 |
20 | private final CategoryRepository categoryRepository;
21 |
22 | public List findAll() {
23 | log.debug("Request to get all Categories");
24 | return this.categoryRepository.findAll()
25 | .stream()
26 | .map(CategoryService::mapToDto)
27 | .collect(Collectors.toList());
28 | }
29 |
30 | @Transactional(readOnly = true)
31 | public CategoryDto findById(Long id) {
32 | log.debug("Request to get Category : {}", id);
33 | return this.categoryRepository.findById(id).map(CategoryService::mapToDto)
34 | .orElseThrow(IllegalStateException::new);
35 | }
36 |
37 | public CategoryDto create(CategoryDto categoryDto) {
38 | log.debug("Request to create Category : {}", categoryDto);
39 | return mapToDto(this.categoryRepository.save(
40 | new Category(
41 | categoryDto.getName(),
42 | categoryDto.getDescription()
43 | )
44 | ));
45 | }
46 |
47 | public void delete(Long id) {
48 | log.debug("Request to delete Category : {}", id);
49 | this.categoryRepository.deleteById(id);
50 | }
51 |
52 | public static CategoryDto mapToDto(Category category) {
53 | if (category != null) {
54 | return new CategoryDto(
55 | category.getId(),
56 | category.getName(),
57 | category.getDescription()
58 | );
59 | }
60 | return null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/service/ProductService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.ProductDto;
4 | import com.targa.labs.dev.myboutique.productservice.domain.Product;
5 | import com.targa.labs.dev.myboutique.productservice.domain.enumeration.ProductStatus;
6 | import com.targa.labs.dev.myboutique.productservice.repository.CategoryRepository;
7 | import com.targa.labs.dev.myboutique.productservice.repository.ProductRepository;
8 | import lombok.RequiredArgsConstructor;
9 | import lombok.extern.slf4j.Slf4j;
10 | import org.springframework.stereotype.Service;
11 | import org.springframework.transaction.annotation.Transactional;
12 |
13 | import java.util.List;
14 | import java.util.stream.Collectors;
15 |
16 | @RequiredArgsConstructor
17 | @Slf4j
18 | @Service
19 | @Transactional
20 | public class ProductService {
21 |
22 | private final ProductRepository productRepository;
23 | private final CategoryRepository categoryRepository;
24 |
25 | public List findAll() {
26 | log.debug("Request to get all Products");
27 | return this.productRepository.findAll()
28 | .stream()
29 | .map(ProductService::mapToDto)
30 | .collect(Collectors.toList());
31 | }
32 |
33 | @Transactional(readOnly = true)
34 | public ProductDto findById(Long id) {
35 | log.debug("Request to get Product : {}", id);
36 | return this.productRepository.findById(id).map(ProductService::mapToDto).orElse(null);
37 | }
38 |
39 | public ProductDto create(ProductDto productDto) {
40 | log.debug("Request to create Product : {}", productDto);
41 |
42 | return mapToDto(this.productRepository.save(
43 | new Product(
44 | productDto.getName(),
45 | productDto.getDescription(),
46 | productDto.getPrice(),
47 | productDto.getQuantity(),
48 | ProductStatus.valueOf(productDto.getStatus()),
49 | productDto.getSalesCounter(),
50 | this.categoryRepository.findById(productDto.getCategory().getId()).orElse(null)
51 | )));
52 | }
53 |
54 | public void delete(Long id) {
55 | log.debug("Request to delete Product : {}", id);
56 | this.productRepository.deleteById(id);
57 | }
58 |
59 | public static ProductDto mapToDto(Product product) {
60 | if (product != null) {
61 | return new ProductDto(
62 | product.getId(),
63 | product.getName(),
64 | product.getDescription(),
65 | product.getPrice(),
66 | product.getQuantity(),
67 | product.getStatus().name(),
68 | product.getSalesCounter(),
69 | product.getReviews().stream().map(ReviewService::mapToDto).collect(Collectors.toSet()),
70 | CategoryService.mapToDto(product.getCategory())
71 | );
72 | }
73 | return null;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/service/ReviewService.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.service;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.ReviewDto;
4 | import com.targa.labs.dev.myboutique.productservice.domain.Review;
5 | import com.targa.labs.dev.myboutique.productservice.repository.ReviewRepository;
6 | import lombok.RequiredArgsConstructor;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | import java.util.List;
12 | import java.util.stream.Collectors;
13 |
14 | @RequiredArgsConstructor
15 | @Slf4j
16 | @Service
17 | @Transactional
18 | public class ReviewService {
19 |
20 | private final ReviewRepository reviewRepository;
21 |
22 | public List findAll() {
23 | log.debug("Request to get all Reviews");
24 | return this.reviewRepository.findAll()
25 | .stream()
26 | .map(ReviewService::mapToDto)
27 | .collect(Collectors.toList());
28 | }
29 |
30 | @Transactional(readOnly = true)
31 | public ReviewDto findById(Long id) {
32 | log.debug("Request to get Review : {}", id);
33 | return this.reviewRepository.findById(id).map(ReviewService::mapToDto).orElse(null);
34 | }
35 |
36 | public ReviewDto create(ReviewDto reviewDto) {
37 | log.debug("Request to create Review : {}", reviewDto);
38 | return mapToDto(this.reviewRepository.save(
39 | new Review(
40 | reviewDto.getTitle(),
41 | reviewDto.getDescription(),
42 | reviewDto.getRating()
43 | )
44 | ));
45 | }
46 |
47 | public void delete(Long id) {
48 | log.debug("Request to delete Review : {}", id);
49 | this.reviewRepository.deleteById(id);
50 | }
51 |
52 | public static ReviewDto mapToDto(Review review) {
53 | if (review != null) {
54 | return new ReviewDto(
55 | review.getId(),
56 | review.getTitle(),
57 | review.getDescription(),
58 | review.getRating()
59 | );
60 | }
61 | return null;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/web/CategoryResource.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.web;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.CategoryDto;
4 | import lombok.RequiredArgsConstructor;
5 | import org.springframework.web.bind.annotation.*;
6 | import com.targa.labs.dev.myboutique.productservice.service.CategoryService;
7 |
8 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
9 | import java.util.List;
10 |
11 | /**
12 | * @author n.lamouchi
13 | */
14 | @RequiredArgsConstructor
15 | @RestController
16 | @RequestMapping(API + "/categories")
17 | public class CategoryResource {
18 |
19 | private final CategoryService categoryService;
20 |
21 | @GetMapping
22 | public List findAll() {
23 | return this.categoryService.findAll();
24 | }
25 |
26 | @GetMapping("/{id}")
27 | public CategoryDto findById(@PathVariable Long id) {
28 | return this.categoryService.findById(id);
29 | }
30 |
31 | @PostMapping
32 | public CategoryDto create(CategoryDto categoryDto) {
33 | return this.categoryService.create(categoryDto);
34 | }
35 |
36 | @DeleteMapping("/{id}")
37 | public void delete(@PathVariable Long id) {
38 | this.categoryService.delete(id);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/web/ProductResource.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.web;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.ProductDto;
4 | import lombok.RequiredArgsConstructor;
5 | import org.springframework.web.bind.annotation.*;
6 |
7 | import java.util.List;
8 |
9 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
10 | import com.targa.labs.dev.myboutique.productservice.service.ProductService;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @RequiredArgsConstructor
16 | @RestController
17 | @RequestMapping(API + "/products")
18 | public class ProductResource {
19 |
20 | private final ProductService productService;
21 |
22 | @GetMapping
23 | public List findAll() {
24 | return this.productService.findAll();
25 | }
26 |
27 | @GetMapping("/{id}")
28 | public ProductDto findById(@PathVariable Long id) {
29 | return this.productService.findById(id);
30 | }
31 |
32 | @PostMapping
33 | public ProductDto create(@RequestBody ProductDto productDto) {
34 | return this.productService.create(productDto);
35 | }
36 |
37 | @DeleteMapping("/{id}")
38 | public void delete(@PathVariable Long id) {
39 | this.productService.delete(id);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/web/ReviewResource.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.web;
2 |
3 | import com.targa.labs.dev.myboutique.commons.dto.ReviewDto;
4 | import static com.targa.labs.dev.myboutique.commons.utils.Web.API;
5 | import com.targa.labs.dev.myboutique.productservice.service.ReviewService;
6 | import lombok.RequiredArgsConstructor;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import java.util.List;
10 |
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @RequiredArgsConstructor
16 | @RestController
17 | @RequestMapping(API + "/reviews")
18 | public class ReviewResource {
19 |
20 | private final ReviewService reviewService;
21 |
22 | @GetMapping
23 | public List findAll() {
24 | return this.reviewService.findAll();
25 | }
26 |
27 | @GetMapping("/{id}")
28 | public ReviewDto findById(@PathVariable Long id) {
29 | return this.reviewService.findById(id);
30 | }
31 |
32 | @PostMapping
33 | public ReviewDto create(@RequestBody ReviewDto reviewDto) {
34 | return this.reviewService.create(reviewDto);
35 | }
36 |
37 | @DeleteMapping("/{id}")
38 | public void delete(@PathVariable Long id) {
39 | this.reviewService.delete(id);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ProductService/src/main/java/com/targa/labs/dev/myboutique/productservice/web/ZipkinController2.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.productservice.web;
2 |
3 | import java.util.logging.Logger;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | *
9 | * @author n.lamouchi
10 | */
11 | @RestController
12 | public class ZipkinController2 {
13 |
14 | private static final Logger LOG = Logger.getLogger(ZipkinController2.class.getName());
15 |
16 | @GetMapping(value = "/zipkin2")
17 | public String zipkinService1() {
18 | LOG.info("Inside zipkinService 2 ..");
19 | return "Hello...";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ProductService/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | uri: http://localhost:8888
5 | application:
6 | name: product-service
--------------------------------------------------------------------------------
/ProductService/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO CATEGORY (ID, NAME , DESCRIPTION, CREATED_DATE, LAST_MODIFIED_DATE) VALUES (hibernate_sequence.nextval,'Serwel Slim', 'Serwel Celio Coupe Slim', NOW(), NOW());
2 | INSERT INTO CATEGORY (ID, NAME , DESCRIPTION, CREATED_DATE, LAST_MODIFIED_DATE) VALUES (hibernate_sequence.nextval,'Serwel Straight', 'Serwel Celio Coupe Straight', NOW(), NOW());
3 | INSERT INTO CATEGORY (ID, NAME , DESCRIPTION, CREATED_DATE, LAST_MODIFIED_DATE) VALUES (hibernate_sequence.nextval,'Serwel Regular', 'Serwel Celio Coupe Regular', NOW(), NOW());
4 |
5 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLUE-SL', 'Serwel Azreg Slim', 40, 100, 0, 'AVAILABLE', 1, NOW(), NOW());
6 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLUE-ST', 'Serwel Azreg Straight', 40, 100, 0, 'AVAILABLE', 2, NOW(), NOW());
7 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLUE-RE', 'Serwel Azreg Regular', 40, 100, 0, 'AVAILABLE', 3, NOW(), NOW());
8 |
9 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-Yellow-SL', 'Serwel Yellow Slim', 40, 100, 0, 'AVAILABLE', 1, NOW(), NOW());
10 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-Yellow-ST', 'Serwel Yellow Straight', 40, 100, 0, 'AVAILABLE', 2, NOW(), NOW());
11 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-Yellow-RE', 'Serwel Yellow Regular', 40, 100, 0, 'AVAILABLE', 3, NOW(), NOW());
12 |
13 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLACK-SL', 'Serwel BLACK Slim', 40, 100, 0, 'AVAILABLE', 1, NOW(), NOW());
14 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLACK-ST', 'Serwel BLACK Straight', 40, 100, 0, 'AVAILABLE', 2, NOW(), NOW());
15 | INSERT INTO PRODUCT (ID, NAME , DESCRIPTION , PRICE , QUANTITY , SALES_COUNTER , STATUS , CATEGORY_ID, CREATED_DATE , LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'QC35-BLACK-RE', 'Serwel BLACK Regular', 40, 100, 0, 'AVAILABLE', 3, NOW(), NOW());
16 |
17 | INSERT INTO REVIEW (ID, TEXT, DESCRIPTION, RATING, CREATED_DATE, LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'Meilleur rapport qualité/prix', 'Meilleur rapport qualité/prix', 4, NOW(), NOW());
18 | INSERT INTO REVIEW (ID, TEXT, DESCRIPTION, RATING, CREATED_DATE, LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'Couleur pas persistente', 'La couleur disparait au bout de deux lavages', 1, NOW(), NOW());
19 | INSERT INTO REVIEW (ID, TEXT, DESCRIPTION, RATING, CREATED_DATE, LAST_MODIFIED_DATE ) VALUES (hibernate_sequence.nextval, 'Meilleur rapport qualité/prix', 'Meilleur rapport qualité/prix', 5, NOW(), NOW());
20 |
21 | INSERT INTO PRODUCT_REVIEWS VALUES (4 , 13);
22 | INSERT INTO PRODUCT_REVIEWS VALUES (6 , 14);
23 | INSERT INTO PRODUCT_REVIEWS VALUES (7 , 15);
24 |
--------------------------------------------------------------------------------
/myboutique-commons/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.targa.labs.dev
5 | myboutique-commons
6 | 1.0.0-SNAPSHOT
7 | jar
8 |
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 2.2.2.RELEASE
13 |
14 |
15 |
16 |
17 |
18 | org.projectlombok
19 | lombok
20 |
21 |
22 | com.fasterxml.jackson.core
23 | jackson-annotations
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-data-jpa
28 |
29 |
30 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/domain/AbstractEntity.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.commons.domain;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 | import org.springframework.data.annotation.CreatedDate;
7 | import org.springframework.data.annotation.LastModifiedDate;
8 | import org.springframework.data.jpa.domain.support.AuditingEntityListener;
9 |
10 | import javax.persistence.*;
11 | import java.io.Serializable;
12 | import java.time.Instant;
13 |
14 | /**
15 | * Base Entity class for entities which will hold creation and last modification date.
16 | */
17 | @Getter
18 | @Setter
19 | @MappedSuperclass
20 | @EntityListeners(AuditingEntityListener.class)
21 | public abstract class AbstractEntity implements Serializable {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | @Id
26 | @GeneratedValue(strategy = GenerationType.AUTO)
27 | private Long id;
28 |
29 | @CreatedDate
30 | @Column(name = "created_date", nullable = false)
31 | @JsonIgnore
32 | private Instant createdDate = Instant.now();
33 |
34 | @LastModifiedDate
35 | @Column(name = "last_modified_date")
36 | @JsonIgnore
37 | private Instant lastModifiedDate = Instant.now();
38 |
39 | }
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/AddressDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class AddressDto {
19 | private String address1;
20 | private String address2;
21 | private String city;
22 | private String postcode;
23 | private String country;
24 | }
25 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/CartDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class CartDto {
19 | private Long id;
20 | private Long orderId;
21 | private CustomerDto customerDto;
22 | private String status;
23 | }
24 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/CategoryDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class CategoryDto {
19 | private Long id;
20 | private String name;
21 | private String description;
22 | }
23 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/CustomerDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class CustomerDto {
19 | private Long id;
20 | private String firstName;
21 | private String lastName;
22 | private String email;
23 | private String telephone;
24 | }
25 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/OrderDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | import java.math.BigDecimal;
13 | import java.time.ZonedDateTime;
14 | import java.util.Set;
15 |
16 | /**
17 | *
18 | * @author n.lamouchi
19 | */
20 | @Data
21 | @NoArgsConstructor
22 | @AllArgsConstructor
23 | public class OrderDto {
24 | private Long id;
25 | private BigDecimal totalPrice;
26 | private String status;
27 | private ZonedDateTime shipped;
28 | private PaymentDto payment;
29 | private AddressDto shipmentAddress;
30 | private Set orderItems;
31 | }
32 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/OrderItemDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | *
14 | * @author n.lamouchi
15 | */
16 | @Data
17 | @NoArgsConstructor
18 | @AllArgsConstructor
19 | public class OrderItemDto {
20 | private Long id;
21 | private Long quantity;
22 | private Long productId;
23 | private Long orderId;
24 | }
25 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/PaymentDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class PaymentDto {
19 | private Long id;
20 | private String paypalPaymentId;
21 | private String status;
22 | private Long orderId;
23 | }
24 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/ProductDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | import java.math.BigDecimal;
13 | import java.util.Set;
14 |
15 | /**
16 | * @author n.lamouchi
17 | */
18 | @Data
19 | @NoArgsConstructor
20 | @AllArgsConstructor
21 | public class ProductDto {
22 | private Long id;
23 | private String name;
24 | private String description;
25 | private BigDecimal price;
26 | private Integer quantity;
27 | private String status;
28 | private Integer salesCounter;
29 | private Set reviews;
30 | private CategoryDto category;
31 | }
32 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/dto/ReviewDto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package com.targa.labs.dev.myboutique.commons.dto;
7 |
8 | import lombok.AllArgsConstructor;
9 | import lombok.Data;
10 | import lombok.NoArgsConstructor;
11 |
12 | /**
13 | * @author n.lamouchi
14 | */
15 | @Data
16 | @NoArgsConstructor
17 | @AllArgsConstructor
18 | public class ReviewDto {
19 | private Long id;
20 | private String title;
21 | private String description;
22 | private Long rating;
23 | }
24 |
--------------------------------------------------------------------------------
/myboutique-commons/src/main/java/com/targa/labs/dev/myboutique/commons/utils/Web.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.commons.utils;
2 |
3 | /**
4 | *
5 | * @author n.lamouchi
6 | */
7 | public class Web {
8 | public static final String API = "/api";
9 | }
10 |
--------------------------------------------------------------------------------
/myboutique-config-server/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/myboutique-config-server/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use an OpenJDK Runtime as a parent image
2 | FROM openjdk:8-jre-alpine
3 | # Add Maintainer Info
4 | LABEL maintainer="lnibrass@gmail.com"
5 | # Define environment variables
6 | ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
7 | JAVA_OPTS=""
8 | # Set the working directory to /app
9 | WORKDIR /app
10 | # Copy the executable into the container at /app
11 | ADD target/configserver-1.0.0-SNAPSHOT.jar app.jar
12 | # Make port 8080 available to the world outside this container
13 | EXPOSE 8888
14 | # Run app.jar when the container launches
15 | CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
--------------------------------------------------------------------------------
/myboutique-config-server/nbactions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | run
5 |
6 | jar
7 |
8 |
9 | spring-boot:run
10 |
11 |
12 | -noverify -XX:TieredStopAtLevel=1
13 | com.targa.labs.dev.myboutique.configserver.ConfigserverApplication
14 | always
15 |
16 |
17 |
18 | debug
19 |
20 | jar
21 |
22 |
23 | spring-boot:run
24 |
25 |
26 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -noverify -XX:TieredStopAtLevel=1
27 | com.targa.labs.dev.myboutique.configserver.ConfigserverApplication
28 | always
29 | true
30 |
31 |
32 |
33 | profile
34 |
35 | jar
36 |
37 |
38 | process-classes
39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
40 |
41 |
42 | -classpath %classpath com.targa.labs.dev.myboutique.configserver.ConfigserverApplication
43 | java
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/myboutique-config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.targa.labs.dev.myboutique
7 | configserver
8 | 1.0.0-SNAPSHOT
9 | jar
10 |
11 | configserver
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.2.2.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 | Hoxton.SR1
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-actuator
32 |
33 |
34 | org.springframework.cloud
35 | spring-cloud-config-server
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 | test
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.cloud
49 | spring-cloud-dependencies
50 | ${spring-cloud.version}
51 | pom
52 | import
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 | com.spotify
65 | dockerfile-maven-plugin
66 | 1.4.13
67 |
68 | nebrass/${project.artifactId}
69 | ${project.version}
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/java/com/targa/labs/dev/myboutique/configserver/ConfigserverApplication.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.configserver;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | @EnableConfigServer
8 | @SpringBootApplication
9 | public class ConfigserverApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ConfigserverApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8888
3 |
4 | spring:
5 | profiles:
6 | active: native
7 | application:
8 | name: config-server
9 | cloud:
10 | config:
11 | server:
12 | native:
13 | search-locations: classpath:/configurations
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/application.yml:
--------------------------------------------------------------------------------
1 | eureka:
2 | instance:
3 | hostname: localhost
4 | client:
5 | service-url:
6 | defaultZone: http://localhost:8761/eureka/
7 |
8 | name:
9 | value: nebrass
10 |
11 | spring:
12 | jpa:
13 | properties:
14 | hibernate:
15 | dialect: org.hibernate.dialect.H2Dialect
16 | sleuth:
17 | sampler:
18 | probability: 1
19 | h2:
20 | console:
21 | enabled: true
22 |
23 | logstash:
24 | host: localhost
25 | port: 5000
26 | queue-size: 512
27 |
28 | management:
29 | endpoints:
30 | web:
31 | exposure:
32 | include: "*"
33 |
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/customer-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9992
3 | spring:
4 | application:
5 | name: customer-service
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/discovery-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8761
3 |
4 | eureka:
5 | instance:
6 | hostname: localhost
7 | client:
8 | registerWithEureka: false
9 | fetchRegistry: false
10 | serviceUrl:
11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/gateway-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8222
3 | zuul:
4 | routes:
5 | order:
6 | path: /order/**
7 | serviceId: order-service
8 | product:
9 | path: /product/**
10 | serviceId: product-service
11 | customer:
12 | path: /customer/**
13 | serviceId: customer-service
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/hystrix-dashboard.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8988
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/order-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9991
3 | spring:
4 | application:
5 | name: order-service
--------------------------------------------------------------------------------
/myboutique-config-server/src/main/resources/configurations/product-service.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9990
3 | spring:
4 | application:
5 | name: product-service
--------------------------------------------------------------------------------
/myboutique-config-server/src/test/java/com/targa/labs/dev/myboutique/configserver/ConfigserverApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.targa.labs.dev.myboutique.configserver;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ConfigserverApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------