Add test for DI constructability of DeleteReplyPage
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnbookmarkPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.utils.also
5 import net.pterodactylus.sone.utils.isGET
6 import net.pterodactylus.sone.utils.isPOST
7 import net.pterodactylus.sone.utils.parameters
8 import net.pterodactylus.sone.web.WebInterface
9 import net.pterodactylus.sone.web.page.FreenetRequest
10 import net.pterodactylus.util.template.Template
11 import net.pterodactylus.util.template.TemplateContext
12
13 /**
14  * Page that lets the user unbookmark a post.
15  */
16 class UnbookmarkPage(template: Template, webInterface: WebInterface):
17                 SoneTemplatePage("unbookmark.html", webInterface, template, "Page.Unbookmark.Title") {
18
19         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
20                 when {
21                         freenetRequest.isGET && (freenetRequest.parameters["post"] == "allNotLoaded") -> {
22                                 webInterface.core.bookmarkedPosts
23                                                 .filterNot(Post::isLoaded)
24                                                 .forEach(webInterface.core::unbookmarkPost)
25                                 throw RedirectException("bookmarks.html")
26                         }
27                         freenetRequest.isPOST -> {
28                                 freenetRequest.parameters["post", 36]
29                                                 ?.let(webInterface.core::getPost)
30                                                 ?.also(webInterface.core::unbookmarkPost)
31                                 throw RedirectException(freenetRequest.parameters["returnPage", 256])
32                         }
33                 }
34         }
35
36 }