Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jun 24, 2020
1 parent 138f9f3 commit 32c9af1
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 0 deletions.
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);
}

}
10 changes: 10 additions & 0 deletions config-service/src/main/resources/application.properties
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
74 changes: 74 additions & 0 deletions lottery-microservice/pom.xml
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>
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));
}
}
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 + "]";
}

}
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);

}
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 lottery-microservice/src/main/resources/application.properties
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=*
4 changes: 4 additions & 0 deletions lottery-microservice/src/main/resources/bootstrap.properties
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

0 comments on commit 32c9af1

Please sign in to comment.