dceapi_rs/services/
news.rs1use std::collections::HashSet;
4use std::sync::LazyLock;
5
6use crate::error::{Error, Result};
7use crate::http::{BaseClient, RequestOptions};
8use crate::models::{GetArticleByPageRequest, GetArticleByPageResponse};
9
10const PATH_GET_ARTICLE_BY_PAGE: &str = "/dceapi/cms/info/articleByPage";
12
13static VALID_COLUMN_IDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
21 let mut set = HashSet::new();
22 set.insert("244"); set.insert("245"); set.insert("246"); set.insert("248"); set.insert("1076"); set.insert("242"); set
29});
30
31pub fn is_valid_column_id(column_id: &str) -> bool {
33 VALID_COLUMN_IDS.contains(column_id)
34}
35
36#[derive(Debug, Clone)]
38pub struct NewsService {
39 client: BaseClient,
40}
41
42impl NewsService {
43 pub fn new(client: BaseClient) -> Self {
45 NewsService { client }
46 }
47
48 pub async fn get_article_by_page(
62 &self,
63 mut req: GetArticleByPageRequest,
64 opts: Option<RequestOptions>,
65 ) -> Result<GetArticleByPageResponse> {
66 if !is_valid_column_id(&req.column_id) {
68 return Err(Error::validation(
69 "column_id",
70 "invalid column_id, must be one of: 244, 245, 246, 248, 1076, 242",
71 ));
72 }
73
74 if req.site_id == 0 {
76 req.site_id = 5;
77 }
78
79 self.client
80 .do_post(PATH_GET_ARTICLE_BY_PAGE, &req, opts)
81 .await
82 }
83}