From 4036d09f337772ac38c13410ab2ac462a42b3311 Mon Sep 17 00:00:00 2001 From: crlwingen Date: Mon, 10 Oct 2022 19:38:02 +0800 Subject: [PATCH 1/2] Added Services, Controllers & View to display jokes. --- .gitignore | 48 +++++++++++-------- .../controllers/JokeController.java | 23 +++++++++ .../chucknorris/services/JokeService.java | 6 +++ .../chucknorris/services/JokeServiceImpl.java | 19 ++++++++ src/main/resources/templates/index.html | 11 +++++ 5 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 src/main/java/guru/springframework/chucknorris/controllers/JokeController.java create mode 100644 src/main/java/guru/springframework/chucknorris/services/JokeService.java create mode 100644 src/main/java/guru/springframework/chucknorris/services/JokeServiceImpl.java create mode 100644 src/main/resources/templates/index.html diff --git a/.gitignore b/.gitignore index a1c2a238a..549e00a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,33 @@ -# Compiled class file -*.class +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# BlueJ files -*.ctxt +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +### VS Code ### +.vscode/ diff --git a/src/main/java/guru/springframework/chucknorris/controllers/JokeController.java b/src/main/java/guru/springframework/chucknorris/controllers/JokeController.java new file mode 100644 index 000000000..05c0bfc40 --- /dev/null +++ b/src/main/java/guru/springframework/chucknorris/controllers/JokeController.java @@ -0,0 +1,23 @@ +package guru.springframework.chucknorris.controllers; + +import guru.springframework.chucknorris.services.JokeService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class JokeController { + + private final JokeService jokeService; + + public JokeController(JokeService jokeService) { + this.jokeService = jokeService; + } + + @RequestMapping({"/", ""}) + public String showJoke(Model model) { + model.addAttribute("joke", jokeService.getJoke()); + + return "index"; + } +} diff --git a/src/main/java/guru/springframework/chucknorris/services/JokeService.java b/src/main/java/guru/springframework/chucknorris/services/JokeService.java new file mode 100644 index 000000000..1b90b7708 --- /dev/null +++ b/src/main/java/guru/springframework/chucknorris/services/JokeService.java @@ -0,0 +1,6 @@ +package guru.springframework.chucknorris.services; + +public interface JokeService { + + String getJoke(); +} diff --git a/src/main/java/guru/springframework/chucknorris/services/JokeServiceImpl.java b/src/main/java/guru/springframework/chucknorris/services/JokeServiceImpl.java new file mode 100644 index 000000000..ad6164169 --- /dev/null +++ b/src/main/java/guru/springframework/chucknorris/services/JokeServiceImpl.java @@ -0,0 +1,19 @@ +package guru.springframework.chucknorris.services; + +import guru.springframework.norris.chuck.ChuckNorrisQuotes; +import org.springframework.stereotype.Service; + +@Service +public class JokeServiceImpl implements JokeService { + + private final ChuckNorrisQuotes chuckNorrisQuotes; + + public JokeServiceImpl() { + this.chuckNorrisQuotes = new ChuckNorrisQuotes(); + } + + @Override + public String getJoke() { + return chuckNorrisQuotes.getRandomQuote(); + } +} diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 000000000..8caac625c --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,11 @@ + + + + + Chuck Norris Jokes + + +

Chuck Norris Joke

+ + + \ No newline at end of file From 785a55ac689495e2091d7f299b41acaeb1aeb307 Mon Sep 17 00:00:00 2001 From: crlwingen Date: Mon, 10 Oct 2022 19:48:02 +0800 Subject: [PATCH 2/2] Created custom banner. Closes #1 --- src/main/resources/banner.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/banner.txt diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 000000000..deff0b103 --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,7 @@ + _______ _______ ______ ___ __ _ _______ _______ ______ _______ __ __ _______ _ _ _______ ______ ___ _ _______ __ __ ______ __ __ +| || || _ | | | | | | || | | || _ | | _ || |_| || || | _ | || || _ | | | | | | || | | || _ | | | | | +| _____|| _ || | || | | | |_| || ___| | ___|| | || | |_| || || ___|| || || || _ || | || | |_| | | ___|| | | || | || | | | | +| |_____ | |_| || |_||_ | | | || | __ | |___ | |_||_ | || || |___ | || | | || |_||_ | _| | | __ | |_| || |_||_ | |_| | +|_____ || ___|| __ || | | _ || || | | ___|| __ || || || ___|| || |_| || __ || |_ | || || || __ || | + _____| || | | | | || | | | | || |_| | | | | | | || _ || ||_|| || |___ | _ || || | | || _ | | |_| || || | | || | +|_______||___| |___| |_||___| |_| |__||_______| |___| |___| |_||__| |__||_| |_||_______||__| |__||_______||___| |_||___| |_| |_______||_______||___| |_||_______| \ No newline at end of file