db/heromodels/src/models/projects/base.rs
2025-06-19 13:18:10 +03:00

228 lines
5.2 KiB
Rust

// heromodels/src/models/projects/base.rs
use heromodels_core::{BaseModelData, BaseModelDataOps, Model};
#[cfg(feature = "rhai")]
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};
use strum_macros::Display; // Made unconditional as Display derive is used on non-rhai-gated enums
// --- Enums ---
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Display)]
pub enum Priority {
Critical,
High,
Medium,
Low,
None,
}
impl Default for Priority {
fn default() -> Self {
Priority::None
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Display)]
pub enum Status {
Todo,
InProgress,
Review,
Done,
Archived,
}
impl Default for Status {
fn default() -> Self {
Status::Todo
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Display)]
pub enum ItemType {
Epic,
Story,
Task,
Bug,
Improvement,
Feature,
}
impl Default for ItemType {
fn default() -> Self {
ItemType::Task
}
}
// --- Structs ---
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "rhai", derive(CustomType))]
pub struct Project {
pub base_data: BaseModelData,
pub name: String,
pub description: String,
pub owner_id: u32,
pub member_ids: Vec<u32>,
pub board_ids: Vec<u32>,
pub sprint_ids: Vec<u32>,
pub epic_ids: Vec<u32>,
pub tags: Vec<String>,
pub status: Status,
pub priority: Priority,
pub item_type: ItemType,
}
impl BaseModelDataOps for Project {
fn get_base_data_mut(&mut self) -> &mut BaseModelData {
&mut self.base_data
}
}
impl Model for Project {
fn get_id(&self) -> u32 {
self.base_data.id
}
fn db_prefix() -> &'static str {
"prj"
}
fn base_data_mut(&mut self) -> &mut BaseModelData {
&mut self.base_data
}
}
impl Project {
pub fn new(_id: u32, name: String, description: String, owner_id: u32) -> Self {
Self {
base_data: BaseModelData::new(),
name,
description,
owner_id,
member_ids: Vec::new(),
board_ids: Vec::new(),
sprint_ids: Vec::new(),
epic_ids: Vec::new(),
tags: Vec::new(),
status: Status::default(),
priority: Priority::default(),
item_type: ItemType::default(),
}
}
// Builder methods
pub fn name(mut self, name: String) -> Self {
self.name = name;
self
}
pub fn description(mut self, description: String) -> Self {
self.description = description;
self
}
pub fn owner_id(mut self, owner_id: u32) -> Self {
self.owner_id = owner_id;
self
}
pub fn add_member_id(mut self, member_id: u32) -> Self {
self.member_ids.push(member_id);
self
}
pub fn member_ids(mut self, member_ids: Vec<u32>) -> Self {
self.member_ids = member_ids;
self
}
pub fn add_board_id(mut self, board_id: u32) -> Self {
self.board_ids.push(board_id);
self
}
pub fn board_ids(mut self, board_ids: Vec<u32>) -> Self {
self.board_ids = board_ids;
self
}
pub fn add_sprint_id(mut self, sprint_id: u32) -> Self {
self.sprint_ids.push(sprint_id);
self
}
pub fn sprint_ids(mut self, sprint_ids: Vec<u32>) -> Self {
self.sprint_ids = sprint_ids;
self
}
pub fn add_epic_id(mut self, epic_id: u32) -> Self {
self.epic_ids.push(epic_id);
self
}
pub fn epic_ids(mut self, epic_ids: Vec<u32>) -> Self {
self.epic_ids = epic_ids;
self
}
pub fn add_tag(mut self, tag: String) -> Self {
self.tags.push(tag);
self
}
pub fn tags(mut self, tags: Vec<String>) -> Self {
self.tags = tags;
self
}
pub fn status(mut self, status: Status) -> Self {
self.status = status;
self
}
pub fn priority(mut self, priority: Priority) -> Self {
self.priority = priority;
self
}
pub fn item_type(mut self, item_type: ItemType) -> Self {
self.item_type = item_type;
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "rhai", derive(CustomType))]
pub struct Label {
pub base_data: BaseModelData,
pub name: String,
pub color: String, // Hex color code
}
impl BaseModelDataOps for Label {
fn get_base_data_mut(&mut self) -> &mut BaseModelData {
&mut self.base_data
}
}
impl Model for Label {
fn get_id(&self) -> u32 {
self.base_data.id
}
fn db_prefix() -> &'static str {
"lbl"
}
fn base_data_mut(&mut self) -> &mut BaseModelData {
&mut self.base_data
}
}
impl Label {
pub fn new(id: u32, name: String, color: String) -> Self {
let mut base_data = BaseModelData::new();
base_data.update_id(id);
Self {
base_data,
name,
color,
}
}
// Builder methods
pub fn name(mut self, name: String) -> Self {
self.name = name;
self
}
pub fn color(mut self, color: String) -> Self {
self.color = color;
self
}
}