added controller and service

This commit is contained in:
marius 2019-01-06 15:12:58 +01:00
parent 64bf644dd3
commit a77f7f14db
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.becausesec.chuckjokes.controllers
import com.becausesec.chuckjokes.services.JokeService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping
@Controller
class JokeController {
@Autowired
lateinit var jokeService: JokeService
@RequestMapping(value=["/", ""])
fun showJoke(model : Model) : String {
model.addAttribute("joke", jokeService.joke)
return "chucknorris"
}
}

View File

@ -0,0 +1,17 @@
package com.becausesec.chuckjokes.services
import guru.springframework.norris.chuck.ChuckNorrisQuotes
import org.springframework.stereotype.Service
@Service
interface JokeService {
val joke:String
}
class JokeServiceImpl:JokeService {
val chuckNorrisQuotes : ChuckNorrisQuotes = ChuckNorrisQuotes()
override val joke: String
get() = chuckNorrisQuotes.randomQuote
}