diff src/delete.js.luan @ 16:bff178656073

delete function
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Jul 2022 22:42:42 -0600
parents
children 0c1b820fff34
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/delete.js.luan	Wed Jul 06 22:42:42 2022 -0600
@@ -0,0 +1,22 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Post = require "site:/lib/Post.luan"
+local Db = require "site:/lib/Db.luan"
+
+
+return function()
+	local post = Http.request.parameters.post or error()
+	Db.run_in_transaction( function()
+		post = Post.get_by_id(post) or error()
+		post.author_is_current() or error()
+		post.is_deleted = true
+		post.save()
+	end )
+	Io.stdout = Http.response.text_writer()
+%>
+let postDiv = document.querySelector('[post="<%=post.id%>"]');
+postDiv.querySelector('[output]').innerHTML = 'deleted';
+<%
+end