16
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
|
4 local Http = require "luan:http/Http.luan"
|
|
5 local Post = require "site:/lib/Post.luan"
|
|
6 local Db = require "site:/lib/Db.luan"
|
|
7
|
|
8
|
|
9 return function()
|
|
10 local post = Http.request.parameters.post or error()
|
|
11 Db.run_in_transaction( function()
|
|
12 post = Post.get_by_id(post) or error()
|
|
13 post.author_is_current() or error()
|
|
14 post.is_deleted = true
|
|
15 post.save()
|
|
16 end )
|
|
17 Io.stdout = Http.response.text_writer()
|
|
18 %>
|
|
19 let postDiv = document.querySelector('[post="<%=post.id%>"]');
|
|
20 postDiv.querySelector('[output]').innerHTML = 'deleted';
|
|
21 <%
|
|
22 end
|