final db models wip
This commit is contained in:
27
heromodels/src/models/governance/attached_file.rs
Normal file
27
heromodels/src/models/governance/attached_file.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
// heromodels/src/models/governance/attached_file.rs
|
||||
use heromodels_core::BaseModelData;
|
||||
use heromodels_derive::model;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
#[model]
|
||||
pub struct AttachedFile {
|
||||
pub base_data: BaseModelData, // Provides id, created_at, updated_at
|
||||
pub name: String,
|
||||
pub url: String,
|
||||
pub file_type: String, // e.g., "pdf", "image/jpeg", "application/msword"
|
||||
pub size_bytes: u64,
|
||||
// Optional: could add uploader_id: u32 if needed
|
||||
}
|
||||
|
||||
impl AttachedFile {
|
||||
pub fn new(name: String, url: String, file_type: String, size_bytes: u64) -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(),
|
||||
name,
|
||||
url,
|
||||
file_type,
|
||||
size_bytes,
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,4 +2,7 @@
|
||||
// This module will contain the Proposal model and related types.
|
||||
pub mod proposal;
|
||||
|
||||
pub use self::proposal::{Proposal, Ballot, VoteOption, ProposalStatus, VoteEventStatus};
|
||||
pub mod attached_file;
|
||||
|
||||
pub use self::proposal::{Proposal, Ballot, VoteOption, ProposalStatus, VoteEventStatus};
|
||||
pub use self::attached_file::AttachedFile;
|
@@ -3,10 +3,11 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use heromodels_derive::model; // For #[model]
|
||||
use rhai::{CustomType, TypeBuilder};
|
||||
use rhai_autobind_macros::rhai_model_export;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use heromodels_core::BaseModelData;
|
||||
use crate::models::core::Comment;
|
||||
use super::AttachedFile;
|
||||
|
||||
// --- Enums ---
|
||||
|
||||
@@ -29,6 +30,7 @@ impl Default for ProposalStatus {
|
||||
/// VoteEventStatus represents the status of the voting process for a proposal
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum VoteEventStatus {
|
||||
Upcoming, // Voting is scheduled but not yet open
|
||||
Open, // Voting is currently open
|
||||
Closed, // Voting has finished
|
||||
Cancelled, // The voting event was cancelled
|
||||
@@ -36,14 +38,14 @@ pub enum VoteEventStatus {
|
||||
|
||||
impl Default for VoteEventStatus {
|
||||
fn default() -> Self {
|
||||
VoteEventStatus::Open
|
||||
VoteEventStatus::Upcoming
|
||||
}
|
||||
}
|
||||
|
||||
// --- Structs ---
|
||||
|
||||
/// VoteOption represents a specific choice that can be voted on
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType, Default)]
|
||||
pub struct VoteOption {
|
||||
pub id: u8, // Simple identifier for this option
|
||||
pub text: String, // Descriptive text of the option
|
||||
@@ -65,8 +67,8 @@ impl VoteOption {
|
||||
}
|
||||
|
||||
/// Ballot represents an individual vote cast by a user
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType)]
|
||||
#[rhai_model_export(db_type = "std::sync::Arc<crate::db::hero::OurDB>")]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType, Default)]
|
||||
// Removed rhai_model_export macro as it's causing compilation errors
|
||||
#[model] // Has base.Base in V spec
|
||||
pub struct Ballot {
|
||||
pub base_data: BaseModelData,
|
||||
@@ -102,7 +104,7 @@ impl Ballot {
|
||||
|
||||
/// Proposal represents a governance proposal that can be voted upon.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, CustomType)]
|
||||
#[rhai_model_export(db_type = "std::sync::Arc<crate::db::hero::OurDB>")]
|
||||
// Removed rhai_model_export macro as it's causing compilation errors
|
||||
#[model] // Has base.Base in V spec
|
||||
pub struct Proposal {
|
||||
pub base_data: BaseModelData,
|
||||
@@ -113,9 +115,6 @@ pub struct Proposal {
|
||||
pub description: String,
|
||||
pub status: ProposalStatus,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
|
||||
// Voting event aspects
|
||||
pub vote_start_date: DateTime<Utc>,
|
||||
pub vote_end_date: DateTime<Utc>,
|
||||
@@ -123,6 +122,35 @@ pub struct Proposal {
|
||||
pub options: Vec<VoteOption>,
|
||||
pub ballots: Vec<Ballot>, // This will store actual Ballot structs
|
||||
pub private_group: Option<Vec<u32>>, // Optional list of eligible user IDs
|
||||
|
||||
pub tags: Vec<String>,
|
||||
pub comments: Vec<Comment>,
|
||||
pub attached_files: Vec<AttachedFile>,
|
||||
pub urgency_score: Option<f32>,
|
||||
}
|
||||
|
||||
impl Default for Proposal {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(),
|
||||
creator_id: "".to_string(),
|
||||
creator_name: String::new(), // Added missing field
|
||||
title: "".to_string(),
|
||||
description: "".to_string(),
|
||||
status: ProposalStatus::Draft,
|
||||
// created_at and updated_at are now in base_data
|
||||
vote_start_date: Utc::now(),
|
||||
vote_end_date: Utc::now(),
|
||||
vote_status: VoteEventStatus::Upcoming,
|
||||
options: vec![],
|
||||
ballots: vec![],
|
||||
private_group: None,
|
||||
tags: vec![],
|
||||
comments: vec![],
|
||||
attached_files: vec![],
|
||||
urgency_score: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Proposal {
|
||||
@@ -142,10 +170,8 @@ impl Proposal {
|
||||
title: impl ToString,
|
||||
description: impl ToString,
|
||||
status: ProposalStatus,
|
||||
created_at: DateTime<Utc>,
|
||||
updated_at: DateTime<Utc>,
|
||||
vote_start_date: DateTime<Utc>,
|
||||
vote_end_date: DateTime<Utc>,
|
||||
tags: Vec<String>,
|
||||
urgency_score: Option<f32>,
|
||||
) -> Self {
|
||||
let mut base_data = BaseModelData::new();
|
||||
if let Some(id) = id {
|
||||
@@ -159,14 +185,16 @@ impl Proposal {
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
status,
|
||||
created_at,
|
||||
updated_at,
|
||||
vote_start_date,
|
||||
vote_end_date,
|
||||
vote_status: VoteEventStatus::Open, // Default to open when created
|
||||
vote_start_date: Utc::now(),
|
||||
vote_end_date: Utc::now(),
|
||||
vote_status: VoteEventStatus::Upcoming,
|
||||
options: Vec::new(),
|
||||
ballots: Vec::new(),
|
||||
private_group: None,
|
||||
tags,
|
||||
comments: Vec::new(),
|
||||
attached_files: Vec::new(),
|
||||
urgency_score,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user