use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub enum NewsCategory {
#[default]
Finance,
Company,
Stock,
USMarket,
Global,
Domestic,
Industry,
}
impl NewsCategory {
pub fn to_column_code(&self) -> &'static str {
match self {
NewsCategory::Finance => "102",
NewsCategory::Company => "103",
NewsCategory::Stock => "104",
NewsCategory::USMarket => "105",
NewsCategory::Global => "111",
NewsCategory::Domestic => "106",
NewsCategory::Industry => "115",
}
}
pub fn from_column_code(code: &str) -> Option<Self> {
match code {
"102" => Some(NewsCategory::Finance),
"103" => Some(NewsCategory::Company),
"104" => Some(NewsCategory::Stock),
"105" => Some(NewsCategory::USMarket),
"111" => Some(NewsCategory::Global),
"106" => Some(NewsCategory::Domestic),
"115" => Some(NewsCategory::Industry),
_ => None,
}
}
}
impl std::fmt::Display for NewsCategory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
NewsCategory::Finance => "Finance",
NewsCategory::Company => "Company",
NewsCategory::Stock => "Stock",
NewsCategory::USMarket => "US Market",
NewsCategory::Global => "Global",
NewsCategory::Domestic => "Domestic",
NewsCategory::Industry => "Industry",
};
write!(f, "{}", name)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsArticle {
pub id: String,
pub title: String,
pub digest: String,
pub url: String,
pub url_mobile: Option<String>,
pub source: String,
pub publish_time: DateTime<Utc>,
pub category: NewsCategory,
pub comment_count: u32,
pub has_image: bool,
pub image_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsSearchResult {
pub keyword: String,
pub total_count: u32,
pub page: u32,
pub page_size: u32,
pub articles: Vec<NewsArticle>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsListResult {
pub category: NewsCategory,
pub page: u32,
pub total_pages: u32,
pub articles: Vec<NewsArticle>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewsContent {
pub id: String,
pub title: String,
pub description: String,
pub body_html: String,
pub body_text: String,
pub source: String,
pub author: Option<String>,
pub publish_time: DateTime<Utc>,
pub related_stocks: Vec<String>,
pub images: Vec<String>,
}