afaee6aaa597451220f495c477628fe18c0b3fd2
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / LikePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.isPOST
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s.
14  */
15 class LikePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
16                 LoggedInPage("like.html", "Page.Like.Title", webInterface, loaders, templateRenderer) {
17
18         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 if (soneRequest.isPOST) {
20                         soneRequest.parameters["type", 16]?.also { type ->
21                                 when (type) {
22                                         "post" -> currentSone.addLikedPostId(soneRequest.parameters["post", 36]!!)
23                                         "reply" -> currentSone.addLikedReplyId(soneRequest.parameters["reply", 36]!!)
24                                 }
25                         }
26                         throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
27                 }
28         }
29
30 }