✨ Use new template renderer
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnlikePage.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 unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply].
15  */
16 class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
17                 LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders, templateRenderer) {
18
19         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20                 if (soneRequest.isPOST) {
21                         when (soneRequest.parameters["type"]) {
22                                 "post" -> currentSone.removeLikedPostId(soneRequest.parameters["post"]!!)
23                                 "reply" -> currentSone.removeLikedReplyId(soneRequest.parameters["reply"]!!)
24                         }
25                         throw RedirectException(soneRequest.parameters["returnPage", 256])
26                 }
27         }
28
29 }