Skip to content

Commit fe0ef91

Browse files
author
Andriy Levchenko
committed
added hackster service
1 parent c7e5e78 commit fe0ef91

6 files changed

Lines changed: 186 additions & 0 deletions

File tree

hackster-service/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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>hackster-service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>hackster-service</name>
12+
<description>Hackster Detection 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+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-data-jpa</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-starter-eureka</artifactId>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>com.h2database</groupId>
49+
<artifactId>h2</artifactId>
50+
<scope>runtime</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.projectlombok</groupId>
54+
<artifactId>lombok</artifactId>
55+
<optional>true</optional>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-starter-test</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<dependencyManagement>
65+
<dependencies>
66+
<dependency>
67+
<groupId>org.springframework.cloud</groupId>
68+
<artifactId>spring-cloud-dependencies</artifactId>
69+
<version>${spring-cloud.version}</version>
70+
<type>pom</type>
71+
<scope>import</scope>
72+
</dependency>
73+
</dependencies>
74+
</dependencyManagement>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-maven-plugin</artifactId>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
85+
86+
</project>
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.Data;
4+
import lombok.NoArgsConstructor;
5+
import lombok.NonNull;
6+
import lombok.RequiredArgsConstructor;
7+
8+
import javax.persistence.Entity;
9+
import javax.persistence.GeneratedValue;
10+
import javax.persistence.Id;
11+
12+
/**
13+
* @author Andriy Levchenko
14+
*/
15+
@Data
16+
@NoArgsConstructor
17+
@RequiredArgsConstructor
18+
@Entity
19+
public class Hackster {
20+
@Id @GeneratedValue
21+
private long id;
22+
23+
@NonNull
24+
private String phone;
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.PathVariable;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
/**
10+
* @author Andriy Levchenko
11+
*/
12+
@RestController
13+
@RequestMapping(path = "/hackster")
14+
public class HacksterController {
15+
16+
@Autowired
17+
private HacksterRepository hacksterRepository;
18+
19+
@GetMapping(path = "/{phone}")
20+
public boolean isHackster(@PathVariable(name = "phone") String phone) {
21+
return hacksterRepository.findByPhone(phone).isPresent();
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
import java.util.Optional;
6+
7+
/**
8+
* @author Andriy Levchenko
9+
*/
10+
public interface HacksterRepository extends JpaRepository<Hackster, Long> {
11+
Optional<Hackster> findByPhone(String phone);
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.CommandLineRunner;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8+
import org.springframework.stereotype.Component;
9+
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
import java.util.stream.Stream;
13+
14+
@EnableDiscoveryClient
15+
@SpringBootApplication
16+
public class HacksterServiceApplication {
17+
18+
public static void main(String[] args) {
19+
SpringApplication.run(HacksterServiceApplication.class, args);
20+
}
21+
22+
// dummy data
23+
@Component
24+
class DummyCLR implements CommandLineRunner {
25+
26+
@Autowired
27+
private HacksterRepository hacksterRepository;
28+
29+
@Override
30+
public void run(String... strings) throws Exception {
31+
List<Hackster> hacksters = Stream.of("123", "456", "789").map(Hackster::new).collect(Collectors.toList());
32+
hacksterRepository.save(hacksters);
33+
34+
35+
hacksterRepository.findAll().forEach(System.out::println);
36+
}
37+
}
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port=8082
2+
spring.application.name=hackster-service

0 commit comments

Comments
 (0)