Replace bookmark ajax page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / BookmarkAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.utils.also
4 import net.pterodactylus.sone.utils.emptyToNull
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8
9 /**
10  * AJAX page that lets the user bookmark a post.
11  */
12 class BookmarkAjaxPage(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) {
13
14         override fun requiresLogin() = false
15
16         override fun createJsonObject(request: FreenetRequest) =
17                         request.parameters["post"].emptyToNull
18                                         ?.let(webInterface.core::getPost)
19                                         ?.also(webInterface.core::bookmarkPost)
20                                         ?.let { createSuccessJsonObject() }
21                                         ?: createErrorJsonObject("invalid-post-id")
22
23 }