44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
// heromodels/src/models/core/comment.rs
|
|
use heromodels_core::BaseModelData;
|
|
use heromodels_derive::model;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] // Added PartialEq
|
|
#[model]
|
|
pub struct Comment {
|
|
pub base_data: BaseModelData, // Provides id, created_at, updated_at
|
|
#[index]
|
|
pub user_id: u32, // Maps to commenter_id
|
|
pub content: String, // Maps to text
|
|
pub parent_comment_id: Option<u32>, // For threaded comments
|
|
}
|
|
|
|
impl Comment {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(),
|
|
user_id: 0, // Default, should be set via builder or method
|
|
content: String::new(),
|
|
parent_comment_id: None,
|
|
}
|
|
}
|
|
|
|
// Builder method for user_id
|
|
pub fn user_id(mut self, id: u32) -> Self {
|
|
self.user_id = id;
|
|
self
|
|
}
|
|
|
|
// Builder method for content
|
|
pub fn content(mut self, content: impl ToString) -> Self {
|
|
self.content = content.to_string();
|
|
self
|
|
}
|
|
|
|
// Builder method for parent_comment_id
|
|
pub fn parent_comment_id(mut self, parent_id: Option<u32>) -> Self {
|
|
self.parent_comment_id = parent_id;
|
|
self
|
|
}
|
|
}
|