website/lib/DB/Series.rakumod

36 lines
778 B
Raku
Raw Permalink Normal View History

2025-02-09 01:50:37 -05:00
use v6.e.PREVIEW;
use JSON::Class:auth<zef:vrurg>;
#| A plain markdown post
unit class Series is json(:pretty);
#| The title of a series
has Str:D $.title is required;
#| The description of a series
has Str:D $.desc is required;
#| The ids of the posts in the series, in series order
2025-02-09 02:12:14 -05:00
has Int:D @.post-ids is rw = [];
2025-02-09 02:43:22 -05:00
#| Returns true if this series contains the given post id
method contains-post(Int:D $post-id --> Bool:D) {
if $post-id ~~ any @!post-ids {
True
} else {
False
}
}
2025-02-09 05:28:59 -05:00
#| Returns the date of the lastest post
method latest-post($db) {
my @posts = @!post-ids.map(-> $i {$db.posts{$i}});
if @posts {
my $most-recent-post = @posts.max(*.posted-at);
$most-recent-post.posted-at
} else {
Nil
}
}