annotate src/delete.js.luan @ 35:1ce75c5ab0f7

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 03 Aug 2022 14:13:12 -0600
parents bff178656073
children 0c1b820fff34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Post = require "site:/lib/Post.luan"
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Db = require "site:/lib/Db.luan"
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 return function()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local post = Http.request.parameters.post or error()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 Db.run_in_transaction( function()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 post = Post.get_by_id(post) or error()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 post.author_is_current() or error()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 post.is_deleted = true
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 post.save()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 end )
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 Io.stdout = Http.response.text_writer()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 %>
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 let postDiv = document.querySelector('[post="<%=post.id%>"]');
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 postDiv.querySelector('[output]').innerHTML = 'deleted';
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <%
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 end