use std::collections::HashSet;
use std::sync::LazyLock;
use crate::error::{Error, Result};
use crate::http::{BaseClient, RequestOptions};
use crate::models::{GetArticleByPageRequest, GetArticleByPageResponse};
const PATH_GET_ARTICLE_BY_PAGE: &str = "/dceapi/cms/info/articleByPage";
static VALID_COLUMN_IDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
let mut set = HashSet::new();
set.insert("244"); set.insert("245"); set.insert("246"); set.insert("248"); set.insert("1076"); set.insert("242"); set
});
pub fn is_valid_column_id(column_id: &str) -> bool {
VALID_COLUMN_IDS.contains(column_id)
}
#[derive(Debug, Clone)]
pub struct NewsService {
client: BaseClient,
}
impl NewsService {
pub fn new(client: BaseClient) -> Self {
NewsService { client }
}
pub async fn get_article_by_page(
&self,
mut req: GetArticleByPageRequest,
opts: Option<RequestOptions>,
) -> Result<GetArticleByPageResponse> {
if !is_valid_column_id(&req.column_id) {
return Err(Error::validation(
"column_id",
"invalid column_id, must be one of: 244, 245, 246, 248, 1076, 242",
));
}
if req.site_id == 0 {
req.site_id = 5;
}
self.client
.do_post(PATH_GET_ARTICLE_BY_PAGE, &req, opts)
.await
}
}