Skip to content

Commit 7068f6b

Browse files
author
alex-muliarevych
committed
Added storage service, add save via feign.
1 parent 105c487 commit 7068f6b

9 files changed

Lines changed: 90 additions & 1 deletion

File tree

config/rating-service.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<module>rating-service</module>
1818
<module>hackster-service</module>
1919
<module>realtor-service</module>
20+
<module>storage-service</module>>
2021
</modules>
2122
</project>

realtor-service/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@
4545
<artifactId>lombok</artifactId>
4646
<version>1.16.12</version>
4747
</dependency>
48+
<dependency>
49+
<groupId>io.github.openfeign</groupId>
50+
<artifactId>feign-okhttp</artifactId>
51+
<version>9.3.1</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.github.openfeign</groupId>
55+
<artifactId>feign-gson</artifactId>
56+
<version>9.3.1</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.github.openfeign</groupId>
60+
<artifactId>feign-slf4j</artifactId>
61+
<version>9.3.1</version>
62+
</dependency>
4863
</dependencies>
4964

5065
<dependencyManagement>

realtor-service/src/main/java/com/lohika/jclub/ApartmentRecord.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public class ApartmentRecord {
1717
private String phone;
1818
@NonNull
1919
private String realtorName;
20+
@NonNull
21+
private String mail;
2022
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.lohika.jclub;
2+
3+
import feign.Headers;
4+
import feign.RequestLine;
5+
6+
/**
7+
* Created by omuliarevych on 6/8/17.
8+
*/
9+
public interface ApartmentRecordClient {
10+
11+
@RequestLine("POST /apartmentRecords")
12+
@Headers("Content-Type: application/json")
13+
void storeApartment(ApartmentRecord apartmentRecord);
14+
}

realtor-service/src/main/java/com/lohika/jclub/RealtorController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class RealtorController {
2121
@Autowired
2222
private RestTemplate restTemplate;
2323

24+
@Autowired
25+
private RealtorService realtorService;
26+
2427
@PostMapping("/apartments")
2528
public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
2629
ResponseEntity<Boolean> isHackster =
@@ -29,6 +32,15 @@ public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
2932
log.info("Is hackster " + isHackster);
3033
}
3134

35+
@PostMapping("/storeApartments")
36+
public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
37+
realtorService.storeApartment(apartmentRecord);
38+
/*ApartmentRecordClient apartmentRecordClient = Feign.builder().encoder(new JacksonEncoder())
39+
.decoder(new JacksonDecoder()).target(ApartmentRecordClient.class, "http://storage-service");
40+
apartmentRecordClient.storeApartment(apartmentRecord);*/
41+
log.info("Stored");
42+
}
43+
3244
@RequestMapping("/service-instances/{applicationName}")
3345
public List<ServiceInstance> serviceInstancesByApplicationName(@PathVariable String applicationName) {
3446
return this.discoveryClient.getInstances(applicationName);

realtor-service/src/main/java/com/lohika/jclub/RealtorServiceApplication.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
66
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
7+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
8+
import org.springframework.cloud.netflix.feign.FeignClient;
79
import org.springframework.context.annotation.Bean;
10+
import org.springframework.web.bind.annotation.PostMapping;
811
import org.springframework.web.client.RestTemplate;
912

13+
@EnableFeignClients
1014
@EnableDiscoveryClient
1115
@SpringBootApplication
1216
public class RealtorServiceApplication {
@@ -21,3 +25,9 @@ public RestTemplate restTemplate() {
2125
return new RestTemplate();
2226
}
2327
}
28+
29+
@FeignClient("storage-service")
30+
interface RealtorService {
31+
@PostMapping("/apartmentRecords")
32+
void storeApartment(ApartmentRecord apartmentRecord);
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lohika.jclub;
2+
3+
import lombok.*;
4+
5+
import javax.persistence.Entity;
6+
import javax.persistence.Id;
7+
8+
@NoArgsConstructor
9+
@AllArgsConstructor
10+
@Data
11+
@Entity
12+
public class ApartmentRecord {
13+
@NonNull
14+
private String location;
15+
@NonNull
16+
private double price;
17+
@NonNull
18+
private double sqft;
19+
@NonNull
20+
private String phone;
21+
@NonNull
22+
private String realtorName;
23+
@Id
24+
private String mail;
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
5+
6+
/**
7+
* Created by omuliarevych on 6/8/17.
8+
*/
9+
@RepositoryRestResource
10+
public interface ApartmentRepository extends CrudRepository<ApartmentRecord, String> {
11+
}

0 commit comments

Comments
 (0)