Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package guru.springframework.chucknorris.services;

public interface JokeService {

String getJoke();
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
7 changes: 7 additions & 0 deletions src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_______ _______ ______ ___ __ _ _______ _______ ______ _______ __ __ _______ _ _ _______ ______ ___ _ _______ __ __ ______ __ __
| || || _ | | | | | | || | | || _ | | _ || |_| || || | _ | || || _ | | | | | | || | | || _ | | | | |
| _____|| _ || | || | | | |_| || ___| | ___|| | || | |_| || || ___|| || || || _ || | || | |_| | | ___|| | | || | || | | | |
| |_____ | |_| || |_||_ | | | || | __ | |___ | |_||_ | || || |___ | || | | || |_||_ | _| | | __ | |_| || |_||_ | |_| |
|_____ || ___|| __ || | | _ || || | | ___|| __ || || || ___|| || |_| || __ || |_ | || || || __ || |
_____| || | | | | || | | | | || |_| | | | | | | || _ || ||_|| || |___ | _ || || | | || _ | | |_| || || | | || |
|_______||___| |___| |_||___| |_| |__||_______| |___| |___| |_||__| |__||_| |_||_______||__| |__||_______||___| |_||___| |_| |_______||_______||___| |_||_______|
11 changes: 11 additions & 0 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Chuck Norris Jokes</title>
</head>
<body>
<h1>Chuck Norris Joke</h1>
<span th:text="${joke}"></span>
</body>
</html>