Add dependency injection tests for bookmark page
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / BookmarkPage.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.web.page.FreenetRequest
4 import net.pterodactylus.util.template.Template
5 import net.pterodactylus.util.template.TemplateContext
6 import net.pterodactylus.util.web.Method.POST
7 import javax.inject.Inject
8 import javax.inject.Singleton
9
10 /**
11  * Page that lets the user bookmark a post.
12  */
13 @Singleton
14 class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface)
15         : SoneTemplatePage("bookmark.html", template, "Page.Bookmark.Title", webInterface) {
16
17         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
18                 if (freenetRequest.method == POST) {
19                         val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
20                         val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)
21                         webInterface.core.getPost(postId).orNull()?.let {
22                                 webInterface.core.bookmarkPost(it)
23                         }
24                         throw RedirectException(returnPage)
25                 }
26         }
27
28 }