20 lines
755 B
Kotlin
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)
|
|
}
|
|
} |