diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2020-04-10 13:34:23 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2020-04-10 13:34:23 +0100 |
| commit | 78400d587ea5367d3424333913ff4f94ca3f1908 (patch) | |
| tree | 2cf5f5ff8069740b0b7dd00853a4ea8c13d6e05c /src/main/kotlin/io/jamesbarnett/redditlite/controller | |
| parent | d5a608143ad2250d8b35b9e4a488d39faaf5a021 (diff) | |
| download | reddit-lite-78400d587ea5367d3424333913ff4f94ca3f1908.tar.xz reddit-lite-78400d587ea5367d3424333913ff4f94ca3f1908.zip | |
Reimplement in Kotlin
Diffstat (limited to 'src/main/kotlin/io/jamesbarnett/redditlite/controller')
| -rw-r--r-- | src/main/kotlin/io/jamesbarnett/redditlite/controller/LandingPageController.kt | 13 | ||||
| -rw-r--r-- | src/main/kotlin/io/jamesbarnett/redditlite/controller/SubredditController.kt | 37 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/main/kotlin/io/jamesbarnett/redditlite/controller/LandingPageController.kt b/src/main/kotlin/io/jamesbarnett/redditlite/controller/LandingPageController.kt new file mode 100644 index 0000000..c2881bd --- /dev/null +++ b/src/main/kotlin/io/jamesbarnett/redditlite/controller/LandingPageController.kt @@ -0,0 +1,13 @@ +package io.jamesbarnett.redditlite.controller + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.servlet.ModelAndView + +@Controller +class LandingPageController { + @GetMapping("/") + fun renderLandingPage() : ModelAndView { + return ModelAndView("landing") + } +}
\ No newline at end of file diff --git a/src/main/kotlin/io/jamesbarnett/redditlite/controller/SubredditController.kt b/src/main/kotlin/io/jamesbarnett/redditlite/controller/SubredditController.kt new file mode 100644 index 0000000..182d269 --- /dev/null +++ b/src/main/kotlin/io/jamesbarnett/redditlite/controller/SubredditController.kt @@ -0,0 +1,37 @@ +package io.jamesbarnett.redditlite.controller + +import io.jamesbarnett.redditlite.service.SubredditService +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.bind.annotation.RequestParam +import org.springframework.web.servlet.ModelAndView + +@Controller +@RequestMapping("/r") +class SubredditController (val subredditService: SubredditService) { + + @GetMapping("/{subreddit}") + fun renderPosts(@PathVariable subreddit: String, + @RequestParam("after", required = false) postAfterId: String?, + @RequestParam("showThumbs", defaultValue = "true") showThumbs: Boolean + ): ModelAndView { + val posts = subredditService.getPosts(subreddit, postAfterId) + return ModelAndView("posts") + .addObject("showThumbs", showThumbs) + .addObject("postAfterId", postAfterId) + .addObject("subreddit", subreddit) + .addObject("posts", posts) + .addObject("nextPostId", posts.last().name) + } + + @GetMapping("/{subreddit}/comments/{postId}") + fun renderPostDetail(@PathVariable subreddit: String, @PathVariable postId: String): ModelAndView { + val postDetail = subredditService.getPostDetail(subreddit, postId) + return ModelAndView("postDetail") + .addObject("subreddit", subreddit) + .addObject("postDetail", postDetail) + } +} + |