-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
415e9dc
commit 3cf3eae
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...active-microservice/src/main/java/com/example/crm/CrmReactiveMicroserviceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...microservice/src/main/java/com/example/crm/controller/CustomerReactiveRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
128 changes: 128 additions & 0 deletions
128
crm-reactive-microservice/src/main/java/com/example/crm/document/Customer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ive-microservice/src/main/java/com/example/crm/repository/CustomerReactiveRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
crm-reactive-microservice/src/main/java/com/example/crm/service/CustomerReactiveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
crm-reactive-microservice/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |