Add test for DI constructability of DistrustPage
[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.utils.isPOST
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10
11 /**
12  * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s.
13  */
14 class LikePage(template: Template, webInterface: WebInterface) :
15                 LoggedInPage("like.html", template, "Page.Like.Title", webInterface) {
16
17         override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
18                 if (freenetRequest.isPOST) {
19                         freenetRequest.parameters["type", 16]?.also { type ->
20                                 when (type) {
21                                         "post" -> currentSone.addLikedPostId(freenetRequest.parameters["post", 36]!!)
22                                         "reply" -> currentSone.addLikedReplyId(freenetRequest.parameters["reply", 36]!!)
23                                 }
24                         }
25                         throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)
26                 }
27         }
28
29 }