use serde::{Deserialize, Serialize}; use crate::core::model::{BaseModel, BaseModelData, IndexKey, ModelBuilder}; use crate::impl_model_builder; /// Represents a comment on a model #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Comment { pub base_data: BaseModelData, pub user_id: u32, pub content: String, } impl Comment { /// Create a new comment pub fn new(id: u32) -> Self { Self { base_data: BaseModelData::new(id), user_id: 0, content: String::new(), } } /// Set the user ID pub fn user_id(mut self, id: u32) -> Self { self.user_id = id; self } /// Set the content pub fn content(mut self, content: impl ToString) -> Self { self.content = content.to_string(); self } } impl BaseModel for Comment { fn db_prefix() -> &'static str { "comment" } fn get_id(&self) -> u32 { self.base_data.id } fn db_keys(&self) -> Vec { vec![ IndexKey { name: "user_id", value: self.user_id.to_string(), }, ] } } // Implement ModelBuilder for Comment impl_model_builder!(Comment);