Mercurial Hosting > freedit
comparison src/lib/Post.luan @ 10:de0cbf515ef5
remove author_id
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 30 Jun 2022 11:11:00 -0600 |
| parents | 9674275019bb |
| children | bff178656073 |
comparison
equal
deleted
inserted
replaced
| 9:9674275019bb | 10:de0cbf515ef5 |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | 2 local error = Luan.error |
| 3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
| 4 local set_metatable = Luan.set_metatable or error() | 4 local set_metatable = Luan.set_metatable or error() |
| 5 local Number = require "luan:Number.luan" | |
| 6 local long = Number.long or error() | |
| 7 local Time = require "luan:Time.luan" | 5 local Time = require "luan:Time.luan" |
| 8 local time_now = Time.now or error() | 6 local time_now = Time.now or error() |
| 9 local Html = require "luan:Html.luan" | 7 local Html = require "luan:Html.luan" |
| 10 local html_encode = Html.encode or error() | 8 local html_encode = Html.encode or error() |
| 11 local Db = require "site:/lib/Db.luan" | 9 local Db = require "site:/lib/Db.luan" |
| 18 return Post.new { | 16 return Post.new { |
| 19 id = doc.id | 17 id = doc.id |
| 20 content = doc.content | 18 content = doc.content |
| 21 date = doc.date | 19 date = doc.date |
| 22 author_name = doc.post_author_name | 20 author_name = doc.post_author_name |
| 23 author_id = doc.post_author_id | |
| 24 root_id = doc.post_root_id | 21 root_id = doc.post_root_id |
| 25 | 22 |
| 26 -- root only | 23 -- root only |
| 27 subject = doc.subject | 24 subject = doc.subject |
| 28 is_root = doc.post_is_root == "true" | 25 is_root = doc.post_is_root == "true" |
| 37 type = "post" | 34 type = "post" |
| 38 id = post.id | 35 id = post.id |
| 39 content = post.content or error() | 36 content = post.content or error() |
| 40 date = post.date or time_now() | 37 date = post.date or time_now() |
| 41 post_author_name = post.author_name or error() | 38 post_author_name = post.author_name or error() |
| 42 post_author_id = long(post.author_id) | 39 post_root_id = post.root_id |
| 43 post_root_id = post.root_id and long(post.root_id) | |
| 44 | 40 |
| 45 -- root only | 41 -- root only |
| 46 subject = post.subject | 42 subject = post.subject |
| 47 post_is_root = post.is_root and "true" or nil | 43 post_is_root = post.is_root and "true" or nil |
| 48 | 44 |
| 53 | 49 |
| 54 local metatable = {} | 50 local metatable = {} |
| 55 function metatable.__index(post,key) | 51 function metatable.__index(post,key) |
| 56 if key == "author" then | 52 if key == "author" then |
| 57 local User = require "site:/lib/User.luan" | 53 local User = require "site:/lib/User.luan" |
| 58 return User.get_by_id(post.author_id) | 54 return User.get_by_name(post.author_name) |
| 59 end | 55 end |
| 60 if key == "subject_html" then | 56 if key == "subject_html" then |
| 61 return post.subject and html_encode(post.subject) | 57 return post.subject and html_encode(post.subject) |
| 62 end | 58 end |
| 63 if key == "root" then | 59 if key == "root" then |
| 79 local post = Post.new{ | 75 local post = Post.new{ |
| 80 root_id = post.root_id | 76 root_id = post.root_id |
| 81 parent_id = post.id | 77 parent_id = post.id |
| 82 content = content | 78 content = content |
| 83 author_name = author.name | 79 author_name = author.name |
| 84 author_id = author.id | |
| 85 } | 80 } |
| 86 post.save() | 81 post.save() |
| 87 return post | 82 return post |
| 88 end ) | 83 end ) |
| 89 end | 84 end |
| 101 return Db.run_in_transaction( function() | 96 return Db.run_in_transaction( function() |
| 102 local post = Post.new{ | 97 local post = Post.new{ |
| 103 subject = subject or error() | 98 subject = subject or error() |
| 104 content = content | 99 content = content |
| 105 author_name = author.name | 100 author_name = author.name |
| 106 author_id = author.id | |
| 107 is_root = true | 101 is_root = true |
| 108 } | 102 } |
| 109 post.save() | 103 post.save() |
| 110 post.root_id = post.id or error() | 104 post.root_id = post.id or error() |
| 111 post.save() | 105 post.save() |
