31 lines
991 B
Kotlin
31 lines
991 B
Kotlin
package com.becausesec.chuckjokes.controllers
|
|
|
|
import com.becausesec.chuckjokes.services.JokeService
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
import org.springframework.ui.Model
|
|
import org.springframework.web.bind.annotation.RequestMapping
|
|
import org.springframework.web.bind.annotation.RequestMethod
|
|
import org.springframework.http.MediaType
|
|
import org.springframework.stereotype.Controller
|
|
import org.springframework.web.bind.annotation.GetMapping
|
|
|
|
|
|
@Controller
|
|
class JokeController {
|
|
|
|
@Autowired
|
|
lateinit var jokeService: JokeService
|
|
@RequestMapping(value=["/", ""], method = [RequestMethod.GET])
|
|
fun showJoke(model : Model) : String {
|
|
model.addAttribute("joke", jokeService.joke)
|
|
return "chucknorris"
|
|
}
|
|
|
|
@GetMapping(value=["/joke", ""], produces = [MediaType.APPLICATION_JSON_VALUE])
|
|
fun showJokeJSON(model : Model) : String {
|
|
model.addAttribute("joke", jokeService.jokeJSON)
|
|
return "chucknorris"
|
|
}
|
|
|
|
|
|
} |