✨ Use new template renderer
[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.Template
10 import net.pterodactylus.util.template.TemplateContext
11 import javax.inject.Inject
12
13 /**
14  * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s.
15  */
16 class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17                 LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders, templateRenderer) {
18
19         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20                 if (soneRequest.isPOST) {
21                         soneRequest.parameters["type", 16]?.also { type ->
22                                 when (type) {
23                                         "post" -> currentSone.addLikedPostId(soneRequest.parameters["post", 36]!!)
24                                         "reply" -> currentSone.addLikedReplyId(soneRequest.parameters["reply", 36]!!)
25                                 }
26                         }
27                         throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
28                 }
29         }
30
31 }