1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Dynasty reader's latest chapter.

pub mod sample;

use serde::{Deserialize, Serialize};

use crate::tag::Tag;

/// Dynasty reader's latest chapter listing.
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct LatestListing {
    /// The latest listing's chapters.
    pub chapters: Vec<LatestChapter>,
    /// The latest listing's current page.
    pub current_page: u16,
    /// The latest listing's total pages.
    pub total_pages: u16,
}

impl LatestListing {
    /// Helper method to get the next page number.
    pub fn next_page(&self) -> Option<u16> {
        if self.current_page < self.total_pages {
            Some(self.current_page + 1)
        } else {
            None
        }
    }
}

/// Dynasty reader's latest chapter item.
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct LatestChapter {
    /// The latest chapter's title.
    pub title: String,
    /// The latest chapter's series.
    pub series: Option<String>,
    /// The latest chapter's permalink.
    pub(crate) permalink: String,
    /// The latest chapter's tags.
    pub tags: Vec<Tag>,
}

impl LatestChapter {
    /// Get the latest chapter's absolute path from <https://dynasty-scans.com/>.
    pub fn path(&self) -> String {
        format!("chapters/{}", self.permalink)
    }
}