added controller and service
This commit is contained in:
parent
64bf644dd3
commit
a77f7f14db
@ -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"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user