♻️ Use SoneRequest instead of FreenetRequest
[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.utils.isPOST
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * Page that lets the user unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply].
14  */
15 class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface):
16                 LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface) {
17
18         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
19                 if (soneRequest.isPOST) {
20                         when (soneRequest.parameters["type"]) {
21                                 "post" -> currentSone.removeLikedPostId(soneRequest.parameters["post"]!!)
22                                 "reply" -> currentSone.removeLikedReplyId(soneRequest.parameters["reply"]!!)
23                         }
24                         throw RedirectException(soneRequest.parameters["returnPage", 256])
25                 }
26         }
27
28 }