diff --git a/.gitignore b/.gitignore
index 57f1cb2..9ef9c26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,63 @@
-/.idea/
\ No newline at end of file
+/.idea/
+
+# Compiled class files
+*.class
+
+# Log files
+*.log
+
+# Package files
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# Maven
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+
+# Gradle
+build/
+.gradle/
+!gradle/wrapper/gradle-wrapper.jar
+
+# Eclipse
+.classpath
+.project
+.settings/
+bin/
+
+# IntelliJ
+*.iml
+*.iws
+*.ipr
+out/
+
+# NetBeans
+nbproject/private/
+nbbuild/
+dist/
+nbdist/
+.nb-gradle/
+
+# VS Code
+.vscode/
+
+# OS files
+.DS_Store
+Thumbs.db
+
+# Virtual machine crash logs
+hs_err_pid*
+replay_pid*
diff --git a/.gitignore.txt b/.gitignore.txt
deleted file mode 100644
index 57f1cb2..0000000
--- a/.gitignore.txt
+++ /dev/null
@@ -1 +0,0 @@
-/.idea/
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 09f1083..0a6973e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
+ classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
}
}
diff --git a/pom.xml b/pom.xml
index 63f5cbd..75edc18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,13 +5,13 @@
org.springframework
gs-spring-boot
- pom
+ jar
0.1.0
org.springframework.boot
spring-boot-starter-parent
- 2.0.2.RELEASE
+ 2.7.18
@@ -28,10 +28,24 @@
org.springframework.boot
spring-boot-starter-jdbc
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
com.h2database
h2
+
+ org.springdoc
+ springdoc-openapi-ui
+ 1.7.0
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
diff --git a/src/main/java/hello/Application.java b/src/main/java/hello/Application.java
index 7cf8faf..53605fa 100644
--- a/src/main/java/hello/Application.java
+++ b/src/main/java/hello/Application.java
@@ -5,18 +5,14 @@
import java.util.stream.Collectors;
import hello.model.Customer;
-import hello.model.Quote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class Application implements CommandLineRunner {
@@ -34,25 +30,6 @@ public static void main(String[] args) {
for (String beanName : beanNames) {
System.out.println(beanName);
}
-
- RestTemplate restTemplate = new RestTemplate();
- Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
- log.info(quote.toString());
- }
-
-
- @Bean
- public RestTemplate restTemplate(RestTemplateBuilder builder) {
- return builder.build();
- }
-
- @Bean
- public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
- return args -> {
- Quote quote = restTemplate.getForObject(
- "http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
- log.info(quote.toString());
- };
}
diff --git a/src/main/java/hello/controller/HelloController.java b/src/main/java/hello/controller/HelloController.java
index f3602fa..a1cdfb8 100644
--- a/src/main/java/hello/controller/HelloController.java
+++ b/src/main/java/hello/controller/HelloController.java
@@ -1,23 +1,16 @@
package hello.controller;
+import hello.declaration.SimpleTimeClient;
import hello.declaration.TimeClient;
-import hello.model.SimpleTimeClient;
-import hello.model.Topic;
import hello.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RequestMapping;
import java.time.LocalDate;
import java.time.LocalDateTime;
-import java.time.LocalTime;
import java.time.ZoneId;
-import java.time.chrono.ChronoPeriod;
import java.time.temporal.ChronoUnit;
-import java.util.List;
-import java.util.regex.Pattern;
-import java.util.stream.Collector;
-import java.util.stream.Collectors;
@RestController
public class HelloController {
@@ -43,7 +36,7 @@ public class HelloController {
*
* @return
*/
- @RequestMapping("/datetime")
+ @GetMapping("/datetime")
public String index() {
TimeClient myTimeClient = new SimpleTimeClient();
LocalDateTime localDateTime = LocalDateTime.now();
@@ -63,7 +56,7 @@ public String index() {
*
* @return
*/
- @RequestMapping("/topic/string/operation")
+ @GetMapping("/topic/string/operation")
public String showStringOperation() {
String join = topicService.returnAllTopicIDWithStringSlicing();
@@ -84,7 +77,7 @@ public String showStringOperation() {
* File Operation in Java 8
* @return
*/
- @RequestMapping("/topic/file/operation")
+ @GetMapping("/topic/file/operation")
public String showFileOperation() {
String findAllFilesInPathAndSort = topicService.findAllFilesInPathAndSort();
String findParticularFileInPathAndSort = topicService.findParticularFileInPathAndSort();
diff --git a/src/main/java/hello/controller/TopicController.java b/src/main/java/hello/controller/TopicController.java
index c2e8273..4c30d35 100644
--- a/src/main/java/hello/controller/TopicController.java
+++ b/src/main/java/hello/controller/TopicController.java
@@ -3,8 +3,17 @@
import hello.model.Topic;
import hello.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
import java.util.List;
@RestController
@@ -18,9 +27,9 @@ public class TopicController {
* Get all Topic
* @return
*/
- @RequestMapping("/topic")
- public List getAllTopics() {
- return topicService.getAllTopics();
+ @GetMapping("/topic")
+ public ResponseEntity> getAllTopics() {
+ return ResponseEntity.ok(topicService.getAllTopics());
}
/**
@@ -28,18 +37,19 @@ public List getAllTopics() {
* @param id
* @return
*/
- @RequestMapping("/topic/{id}")
- public Topic getTopicWithID(@PathVariable String id) {
- return topicService.getTopicWithId(id);
+ @GetMapping("/topic/{id}")
+ public ResponseEntity getTopicWithID(@PathVariable String id) {
+ return ResponseEntity.ok(topicService.getTopicWithId(id));
}
/**
* Add a new topic in list
* @param topic
*/
- @RequestMapping(method = RequestMethod.POST, value = "/topic")
- public void addTopic(@RequestBody Topic topic) {
+ @PostMapping("/topic")
+ public ResponseEntity addTopic(@Valid @RequestBody Topic topic) {
topicService.addTopic(topic);
+ return ResponseEntity.status(HttpStatus.CREATED).build();
}
/**
@@ -47,9 +57,10 @@ public void addTopic(@RequestBody Topic topic) {
* @param id
* @param topic
*/
- @RequestMapping(method = RequestMethod.PUT, value = "/topic/{id}")
- public void updateTopic(@PathVariable String id, @RequestBody Topic topic) {
+ @PutMapping("/topic/{id}")
+ public ResponseEntity updateTopic(@PathVariable String id, @Valid @RequestBody Topic topic) {
topicService.updateTopic(id, topic);
+ return ResponseEntity.ok().build();
}
@@ -57,9 +68,10 @@ public void updateTopic(@PathVariable String id, @RequestBody Topic topic) {
* Delete a topic with ID
* @param id
*/
- @RequestMapping(method = RequestMethod.DELETE, value = "/topic/{id}")
- public void deleteTopic(@PathVariable String id) {
+ @DeleteMapping("/topic/{id}")
+ public ResponseEntity deleteTopic(@PathVariable String id) {
topicService.deleteTopic(id);
+ return ResponseEntity.noContent().build();
}
/**
@@ -67,9 +79,9 @@ public void deleteTopic(@PathVariable String id) {
* @param minLength
* @return
*/
- @RequestMapping(value = "/topic/minimum/length/{minLength}")
- public List filterMinimumLengthForId(@PathVariable Integer minLength) {
- return topicService.filterMinimumLengthForId(minLength);
+ @GetMapping("/topic/minimum/length/{minLength}")
+ public ResponseEntity> filterMinimumLengthForId(@PathVariable Integer minLength) {
+ return ResponseEntity.ok(topicService.filterMinimumLengthForId(minLength));
}
@@ -77,9 +89,9 @@ public List filterMinimumLengthForId(@PathVariable Integer minLength) {
* Sort with Id
* @return
*/
- @RequestMapping("/topic/sort")
- public List sortTopicsWithID() {
- return topicService.sortTopicsWithID();
+ @GetMapping("/topic/sort")
+ public ResponseEntity> sortTopicsWithID() {
+ return ResponseEntity.ok(topicService.sortTopicsWithID());
}
diff --git a/src/main/java/hello/declaration/CustomPredicate.java b/src/main/java/hello/declaration/CustomPredicate.java
index 46f0c44..af828ac 100644
--- a/src/main/java/hello/declaration/CustomPredicate.java
+++ b/src/main/java/hello/declaration/CustomPredicate.java
@@ -4,6 +4,7 @@
* Use as a Functional Interface
* @param
*/
+@FunctionalInterface
public interface CustomPredicate {
boolean test(T t);
}
diff --git a/src/main/java/hello/model/SimpleTimeClient.java b/src/main/java/hello/declaration/SimpleTimeClient.java
similarity index 95%
rename from src/main/java/hello/model/SimpleTimeClient.java
rename to src/main/java/hello/declaration/SimpleTimeClient.java
index e4e142a..e1eac43 100644
--- a/src/main/java/hello/model/SimpleTimeClient.java
+++ b/src/main/java/hello/declaration/SimpleTimeClient.java
@@ -1,6 +1,4 @@
-package hello.model;
-
-import hello.declaration.TimeClient;
+package hello.declaration;
import java.time.LocalDate;
import java.time.LocalDateTime;
diff --git a/src/main/java/hello/exception/GlobalExceptionHandler.java b/src/main/java/hello/exception/GlobalExceptionHandler.java
new file mode 100644
index 0000000..55a11d9
--- /dev/null
+++ b/src/main/java/hello/exception/GlobalExceptionHandler.java
@@ -0,0 +1,38 @@
+package hello.exception;
+
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+
+ private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
+
+ @ExceptionHandler(TopicNotFoundException.class)
+ public ResponseEntity