Add palceholder post and update db init
This commit is contained in:
parent
a8e3b30668
commit
fc04245162
3 changed files with 56 additions and 4 deletions
|
@ -10,10 +10,17 @@ use DB::Post;
|
|||
use DB::BlogMeta;
|
||||
use DB::MarkdownPost;
|
||||
use DB::IdrisPost;
|
||||
use DB::PlaceholderPost;
|
||||
|
||||
class Posts is json(:dictionary(:keyof(Int:D), MarkdownPost:D, IdrisPost:D)) {}
|
||||
class Posts is json(
|
||||
:dictionary()
|
||||
:keyof(Int:D),
|
||||
MarkdownPost:D,
|
||||
IdrisPost:D,
|
||||
PlaceholderPost:D,
|
||||
)) {}
|
||||
|
||||
subset PostTypes where MarkdownPost:D | IdrisPost:D;
|
||||
subset PostTypes where MarkdownPost:D | IdrisPost:D | PlaceholderPost:D;
|
||||
|
||||
#| The top level posts database
|
||||
class PostDB is json(:pretty) {
|
||||
|
@ -21,6 +28,8 @@ class PostDB is json(:pretty) {
|
|||
has BlogMeta:D $.meta is required;
|
||||
#| A mapping from post ids to posts
|
||||
has %.posts is Posts;
|
||||
#| The post id to use for placeholder posts
|
||||
has Int $.placeholder-id = 0;
|
||||
|
||||
method TWEAK() {
|
||||
%!posts := Posts.new unless %!posts;
|
||||
|
@ -41,4 +50,14 @@ class PostDB is json(:pretty) {
|
|||
%!posts{$id} = $post;
|
||||
$id
|
||||
}
|
||||
|
||||
#| Initialize a new database
|
||||
method init(BlogMeta:D $meta --> PostDB:D) {
|
||||
my %posts is Posts = Posts.new;
|
||||
%posts{0} = PlaceholderPost.empty;
|
||||
PostDB.new(
|
||||
meta => $meta,
|
||||
posts => %posts,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue