This repository has been archived on 2018-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
url-shortener/src/main/kotlin/net/cismon/urlshortener/controller/UrlRedirectController.kt

20 lines
755 B
Kotlin

package net.cismon.urlshortener.controller
import net.cismon.urlshortener.service.UrlService
import org.springframework.data.rest.webmvc.ResourceNotFoundException
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.servlet.view.RedirectView
@Controller
@RequestMapping("/{uuid}")
class UrlRedirectController(private val urlService: UrlService) {
@GetMapping
fun getUrl(@PathVariable uuid: String): RedirectView {
val url = urlService.getUrl(uuid) ?: throw ResourceNotFoundException()
return RedirectView(url.url)
}
}