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 415e9dc commit 3cf3eae
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.crm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.web.reactive.config.EnableWebFlux;

@SpringBootApplication
@EnableWebFlux
@EnableReactiveMongoRepositories
public class CrmReactiveMicroserviceApplication {

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

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

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.CustomerReactiveService;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("customers")
@CrossOrigin
public class CustomerReactiveRestController {
@Autowired
private CustomerReactiveService customerService;

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

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

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

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

import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;

import com.example.crm.document.Customer;

import reactor.core.publisher.Flux;

public interface CustomerReactiveRepository extends ReactiveMongoRepository<Customer, String>{

@Query("{}")
Flux<Customer> findAllFlux(PageRequest page);

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import com.example.crm.document.Customer;
import com.example.crm.repository.CustomerReactiveRepository;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
public class CustomerReactiveService {
@Autowired
private CustomerReactiveRepository customerRepository;

public Flux<Customer> findAllCustomers(int pagesize, int pageno) {
return customerRepository.findAllFlux(PageRequest.of(pageno, pagesize));
}

public Mono<Customer> findCustomerByIdentity(String identity) {
return customerRepository.findById(identity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# REST API URL BASE
# http(s)://localhost:8200/crm/api/v1
server.address=localhost
server.port=8200

#mongodb configuration
spring.data.mongodb.uri=mongodb://localhost:27017/crm

0 comments on commit 3cf3eae

Please sign in to comment.