Skip to content

Commit 7ef04bd

Browse files
authored
Merge pull request #1 from DivitGitHub/create_simple_rest_api
Create simple rest api
2 parents 7842b4e + 4e6fcc2 commit 7ef04bd

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
.project
3+
.classpath
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.8
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
13+
org.eclipse.jdt.core.compiler.release=disabled
14+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
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.divit.spring-boot-simple-rest-api</groupId>
7+
<artifactId>com.divit.spring-boot-simple-rest-api</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<url>http://maven.apache.org</url>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-web</artifactId>
15+
<version>2.1.1.RELEASE</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>org.projectlombok</groupId>
19+
<artifactId>lombok</artifactId>
20+
<version>1.16.22</version>
21+
<scope>provided</scope>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-compiler-plugin</artifactId>
30+
<version>3.3</version>
31+
<configuration>
32+
<source>1.8</source>
33+
<target>1.8</target>
34+
</configuration>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.divit.springboot.application;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
7+
@SpringBootApplication
8+
@ComponentScan({"com.divit.springboot.application"})
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.divit.springboot.application.controller;
2+
3+
import java.util.List;
4+
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.util.StringUtils;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
import com.divit.springboot.application.model.Candidate;
13+
import com.divit.srpingboot.application.util.CandidatesUtil;
14+
15+
import lombok.extern.slf4j.Slf4j;
16+
17+
@Slf4j
18+
@RestController
19+
@RequestMapping(value = "/api/v1")
20+
public class ApiRestController {
21+
22+
@GetMapping(value = "/candidates")
23+
public ResponseEntity<?> fetchCandidates(@RequestParam(value = "skill", required = false) String skill) {
24+
log.info("Response received. Params: skills {}", skill);
25+
26+
// Simple util to help us get some dummy data
27+
List<Candidate> candidateList = CandidatesUtil.getCandidates();
28+
if (!StringUtils.isEmpty(skill)) {
29+
// Filtering by skill
30+
candidateList.removeIf((candidate) -> !candidate.getSkillsSet().contains(skill.toLowerCase()));
31+
}
32+
33+
return ResponseEntity.ok(candidateList);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.divit.springboot.application.model;
2+
3+
import java.util.Set;
4+
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
public class Candidate {
11+
private String name;
12+
private int experienceYears;
13+
private Set<String> skillsSet;
14+
15+
public Candidate(String name, int experienceYears, Set<String> skillsSet) {
16+
this.name = name;
17+
this.experienceYears = experienceYears;
18+
this.skillsSet = skillsSet;
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.divit.srpingboot.application.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.HashSet;
6+
import java.util.List;
7+
8+
import com.divit.springboot.application.model.Candidate;
9+
10+
public final class CandidatesUtil {
11+
12+
private CandidatesUtil() {
13+
}
14+
15+
public static List<Candidate> getCandidates() {
16+
List<Candidate> candidateList = new ArrayList<>();
17+
candidateList.add(new Candidate("John", 2, new HashSet<String>(Arrays.asList("java", "c#", "c++", "golang"))));
18+
candidateList.add(new Candidate("David", 1, new HashSet<String>(Arrays.asList("javaScript", "c++"))));
19+
candidateList.add(new Candidate("Diana", 4, new HashSet<String>(Arrays.asList("java", "python"))));
20+
candidateList.add(new Candidate("June", 2, new HashSet<String>(Arrays.asList("ruby", "aws", "docker"))));
21+
22+
return candidateList;
23+
}
24+
}

0 commit comments

Comments
 (0)