Skip to content

Commit c7e5e78

Browse files
author
Andriy Levchenko
committed
added rating-service
1 parent 1cfe33d commit c7e5e78

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

rating-service/pom.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.lohika.jclub</groupId>
7+
<artifactId>rating-service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>rating-service</name>
12+
<description>Rating Calculation Service</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.3.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-actuator</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.cloud</groupId>
39+
<artifactId>spring-cloud-starter-config</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.cloud</groupId>
43+
<artifactId>spring-cloud-starter-eureka</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.projectlombok</groupId>
48+
<artifactId>lombok</artifactId>
49+
<version>1.16.16</version>
50+
</dependency>
51+
52+
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-test</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
</dependencies>
59+
60+
<dependencyManagement>
61+
<dependencies>
62+
<dependency>
63+
<groupId>org.springframework.cloud</groupId>
64+
<artifactId>spring-cloud-dependencies</artifactId>
65+
<version>${spring-cloud.version}</version>
66+
<type>pom</type>
67+
<scope>import</scope>
68+
</dependency>
69+
</dependencies>
70+
</dependencyManagement>
71+
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-maven-plugin</artifactId>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
81+
82+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.lohika.jclub;
2+
3+
import lombok.Data;
4+
import lombok.NonNull;
5+
6+
/**
7+
* @author Andriy Levchenko
8+
*/
9+
@Data
10+
public class Apartment {
11+
@NonNull
12+
private String location;
13+
@NonNull
14+
private double price;
15+
@NonNull
16+
private double sqft;
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.web.bind.annotation.PostMapping;
5+
import org.springframework.web.bind.annotation.RequestBody;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import java.math.BigDecimal;
10+
import java.math.MathContext;
11+
import java.math.RoundingMode;
12+
13+
/**
14+
* @author Andriy Levchenko
15+
*/
16+
@RestController
17+
@RequestMapping(path = "/rating")
18+
public class RatingController {
19+
20+
@Value("${rate}")
21+
private int rate;
22+
23+
@PostMapping
24+
public BigDecimal calculateRating(@RequestBody Apartment ap) {
25+
//TODO: add more meaningful calculations
26+
return new BigDecimal((ap.getSqft()/ap.getPrice())*rate, new MathContext(3, RoundingMode.HALF_UP));
27+
}
28+
29+
}
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 org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
7+
@EnableDiscoveryClient
8+
@SpringBootApplication
9+
public class RatingServiceApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(RatingServiceApplication.class, args);
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port=8081
2+
spring.application.name=rating-service

0 commit comments

Comments
 (0)