Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jun 28, 2020
1 parent 50e0f42 commit 6dc2d94
Show file tree
Hide file tree
Showing 53 changed files with 1,505 additions and 68 deletions.
89 changes: 89 additions & 0 deletions crm-microservice-event-sourcesing-cqrs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>crm-microservice-event-sourcesing-cqrs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crm-microservice-event-sourcesing-cqrs</name>
<description>Spring Cloud Gateway</description>

<properties>
<java.version>11</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.24</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.crm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@SpringBootApplication
public class CrmMicroserviceEventSourcesingCqrsApplication {

public static void main(String[] args) {
SpringApplication.run(CrmMicroserviceEventSourcesingCqrsApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.example.crm.config;

import java.util.Date;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.paths.RelativePathProvider;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
@Value("${major.version}")
private String majorVersion;
@Value("${minor.version}")
private String minorVersion;
@Value("${timestamp}")
private long timestamp;
@Value("${server.servlet.context-path}")
private String contextPath;
@Value("${spring.mvc.servlet.path}")
private String servletPath;

@Value("${server.address}")
private String host;

@Value("${server.port}")
private long port;

@Bean
public Docket api(ServletContext servletContext) {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build().host(host.concat(":").concat(Long.toString(port)))
.pathProvider(new RelativePathProvider(servletContext) {
@Override
public String getApplicationBasePath() {
return contextPath;
}
}).apiInfo(apiInfo());
}

private ApiInfo apiInfo() {

return new ApiInfoBuilder().title("Market Service")
.description("<b>Client FrontEnd API</b><br /><br />Updated: [" + (new Date(timestamp)).toString()
+ " ]" + " <script>document.title = \"Market Service\";"
+ " document.getElementById('header').remove();" + "</script>")
.version(majorVersion + "." + minorVersion).build();
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");

registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import com.example.crm.document.Customer;
import com.example.crm.service.CustomerCommandService;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@RestController
@RequestScope
@RequestMapping("customers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import com.example.crm.document.Customer;
import com.example.crm.service.CustomerQueryService;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@RestController
@RequestScope
@RequestMapping("customers")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.example.crm.document;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Document(collection = "customers")
public class Customer {
@Id
private String identity;
private String fullname;
private String homeAddress;
private String businessAddress;
private String email;
private String sms;
private int birthDay;
private String photo;

public Customer() {
}

public Customer(String identity, String fullname, String homeAddress, String businessAddress, String email,
String sms, int birthDay) {
this.identity = identity;
this.fullname = fullname;
this.homeAddress = homeAddress;
this.businessAddress = businessAddress;
this.email = email;
this.sms = sms;
this.birthDay = birthDay;
}

public String getIdentity() {
return identity;
}

public void setIdentity(String identity) {
this.identity = identity;
}

public String getFullname() {
return fullname;
}

public void setFullname(String fullname) {
this.fullname = fullname;
}

public String getHomeAddress() {
return homeAddress;
}

public void setHomeAddress(String homeAddress) {
this.homeAddress = homeAddress;
}

public String getBusinessAddress() {
return businessAddress;
}

public void setBusinessAddress(String businessAddress) {
this.businessAddress = businessAddress;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getSms() {
return sms;
}

public void setSms(String sms) {
this.sms = sms;
}

public int getBirthDay() {
return birthDay;
}

public void setBirthDay(int birthDay) {
this.birthDay = birthDay;
}

public String getPhoto() {
return photo;
}

public void setPhoto(String photo) {
this.photo = photo;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((identity == null) ? 0 : identity.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Customer other = (Customer) obj;
if (identity == null) {
if (other.identity != null)
return false;
} else if (!identity.equals(other.identity))
return false;
return true;
}

@Override
public String toString() {
return "Customer [identity=" + identity + ", fullname=" + fullname + ", homeAddress=" + homeAddress
+ ", businessAddress=" + businessAddress + ", email=" + email + ", sms=" + sms + ", birthDay="
+ birthDay + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.example.crm.events;

import java.util.Date;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
*
* @author Binnur Kurt <binnur.kurt@gmail.com>
*
*/
@Document(collection = "events")
public class CustomerBaseEvent {
@Id
Expand All @@ -11,7 +22,11 @@ public class CustomerBaseEvent {
private long sequenceId;
private String sourceId;
private String identity;

@LastModifiedDate
private Date lastModified;
@CreatedDate
private Date createdAt;

public CustomerBaseEvent() {
}

Expand Down Expand Up @@ -55,6 +70,24 @@ public void setIdentity(String identity) {
this.identity = identity;
}

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getLastModified() {
return lastModified;
}

public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

@Override
public String toString() {
return "CustomerBaseEvent [eventId=" + eventId + ", conversationId=" + conversationId + ", sequenceId="
Expand Down
Loading

0 comments on commit 6dc2d94

Please sign in to comment.