-
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
138f9f3
commit 32c9af1
Showing
9 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
config-service/src/main/java/com/example/ConfigServiceApplication.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,15 @@ | ||
package com.example; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.config.server.EnableConfigServer; | ||
|
||
@SpringBootApplication | ||
@EnableConfigServer | ||
public class ConfigServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ConfigServiceApplication.class, args); | ||
} | ||
|
||
} |
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,10 @@ | ||
server.address=localhost | ||
server.port=3030 | ||
|
||
#spring cloud config configuration | ||
spring.cloud.config.server.git.uri=c:/DEVEL/stage/tmp/config-repo | ||
spring.cloud.config.server.git.clone-on-start=true | ||
|
||
#authentication | ||
spring.security.user.name=root | ||
spring.security.user.password=secret |
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,74 @@ | ||
<?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>lottery-microservice</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>lottery-microservice</name> | ||
<description>Spring Boot Project for Lottery MicroService</description> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</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.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-config</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Hoxton.SR5</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
lottery-microservice/src/main/java/com/example/lottery/controller/LotteryRestController.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,27 @@ | ||
package com.example.lottery.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.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.lottery.dto.LotteryResponse; | ||
import com.example.lottery.service.LotteryService; | ||
|
||
@RestController | ||
@RequestScope | ||
@RequestMapping("numbers") | ||
@CrossOrigin | ||
public class LotteryRestController { | ||
@Autowired | ||
private LotteryService lotteryService; | ||
|
||
// GET http://localhost:8001/lottery/api/v1/numbers?column=10 | ||
@GetMapping(params = {"column"}) | ||
public LotteryResponse getNumbers(@RequestParam int column){ | ||
return new LotteryResponse(lotteryService.draw(column)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
lottery-microservice/src/main/java/com/example/lottery/dto/LotteryResponse.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,28 @@ | ||
package com.example.lottery.dto; | ||
|
||
import java.util.List; | ||
|
||
public class LotteryResponse { | ||
private List<List<Integer>> numbers; | ||
|
||
public LotteryResponse() { | ||
} | ||
|
||
public LotteryResponse(List<List<Integer>> numbers) { | ||
this.numbers = numbers; | ||
} | ||
|
||
public List<List<Integer>> getNumbers() { | ||
return numbers; | ||
} | ||
|
||
public void setNumbers(List<List<Integer>> numbers) { | ||
this.numbers = numbers; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LotteryResponse [numbers=" + numbers + "]"; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
lottery-microservice/src/main/java/com/example/lottery/service/LotteryService.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,9 @@ | ||
package com.example.lottery.service; | ||
|
||
import java.util.List; | ||
|
||
public interface LotteryService { | ||
|
||
List<List<Integer>> draw(int column); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...microservice/src/main/java/com/example/lottery/service/business/SimpleLotteryService.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,38 @@ | ||
package com.example.lottery.service.business; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.example.lottery.service.LotteryService; | ||
|
||
@Service | ||
public class SimpleLotteryService implements LotteryService{ | ||
@Value("${lottery.min}") | ||
private int lotteryMin; | ||
@Value("${lottery.max}") | ||
private int lotteryMax; | ||
@Value("${lottery.size}") | ||
private int lotterySize; | ||
|
||
public List<Integer> draw() { | ||
return ThreadLocalRandom.current().ints(lotteryMin, lotteryMax) | ||
.distinct() | ||
.limit(lotterySize) | ||
.sorted() | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public List<List<Integer>> draw(int column) { | ||
return IntStream.range(0, column) | ||
.mapToObj(i -> this.draw()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
lottery-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,11 @@ | ||
#Rest API URL Design | ||
server.address=localhost | ||
server.port=8001 | ||
server.servlet.context-path=/lottery | ||
spring.mvc.servlet.path=/api/v1 | ||
|
||
spring.application.name=lottery | ||
spring.profiles.active=development | ||
|
||
# actuator | ||
management.endpoints.web.exposure.include=* |
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,4 @@ | ||
# config server | ||
spring.cloud.config.uri=http://localhost:3030 | ||
spring.cloud.config.username=root | ||
spring.cloud.config.password=secret |