Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jun 26, 2020
1 parent fc7bc93 commit 2b87897
Show file tree
Hide file tree
Showing 19 changed files with 763 additions and 2 deletions.
87 changes: 87 additions & 0 deletions crm-microservice/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crm-microservice</name>
<description>Spring Boot Project for CRM Service</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>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>
<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</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

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

</project>
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
@@ -0,0 +1,47 @@
package com.example.crm.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

import com.example.crm.document.Customer;
import com.example.crm.service.CustomerCommandService;

@RestController
@RequestScope
@RequestMapping("customers")
@CrossOrigin
public class CustomerCommandRestController {
@Autowired
private CustomerCommandService customerService;

@PostMapping
public Customer createCustomer(@RequestBody Customer customer) {
return customerService.createCustomer(customer);
}

@PutMapping("{identity}")
public Customer updateCustomer(@PathVariable String identity, @RequestBody Customer customer) {
return customerService.updateCustomerByIdentity(identity, customer);
}

@PatchMapping("{identity}")
public Customer patchCustomer(@PathVariable String identity, @RequestBody Map<String, Object> request) {
return customerService.updateCustomerByIdentity(identity, request);
}

@DeleteMapping("{identity}")
public Customer removeCustomerByIdentity(@PathVariable String identity) {
return customerService.deleteCustomerByIdentity(identity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

import com.example.crm.document.Customer;
import com.example.crm.service.CustomerQueryService;

@RestController
@RequestScope
@RequestMapping("customers")
@CrossOrigin
public class CustomerQueryRestController {
@Autowired
private CustomerQueryService customerService;

@GetMapping(params = { "pagesize", "pageno" })
public List<Customer> getAllCustomers(@RequestParam int pagesize, @RequestParam int pageno) {
return customerService.findAllCustomers(pagesize, pageno);
}

@GetMapping("{identity}")
public Customer getCustomerByIdentity(@PathVariable String identity) {
return customerService.findCustomerByIdentity(identity);
}

}
128 changes: 128 additions & 0 deletions crm-microservice/src/main/java/com/example/crm/document/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.example.crm.document;

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

@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 + "]";
}

}
Loading

0 comments on commit 2b87897

Please sign in to comment.