db/herodb_old/src/models/gov/meeting.rs
2025-04-22 12:53:17 +04:00

189 lines
5.2 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::db::{Model, Storable, DB, DbError, DbResult}; // Import traits from db module
// use std::collections::HashMap; // Removed unused import
// use super::db::Model; // Removed old Model trait import
/// MeetingStatus represents the status of a meeting
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MeetingStatus {
Scheduled,
Completed,
Cancelled,
}
/// AttendeeRole represents the role of an attendee in a meeting
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AttendeeRole {
Coordinator,
Member,
Secretary,
Participant,
Advisor,
Admin,
}
/// AttendeeStatus represents the status of an attendee's participation
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AttendeeStatus {
Confirmed,
Pending,
Declined,
}
/// Attendee represents an attendee of a board meeting
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attendee {
pub id: u32,
pub meeting_id: u32,
pub user_id: u32,
pub name: String,
pub role: AttendeeRole,
pub status: AttendeeStatus,
pub created_at: DateTime<Utc>,
}
impl Attendee {
/// Create a new attendee with default values
pub fn new(
id: u32,
meeting_id: u32,
user_id: u32,
name: String,
role: AttendeeRole,
) -> Self {
Self {
id,
meeting_id,
user_id,
name,
role,
status: AttendeeStatus::Pending,
created_at: Utc::now(),
}
}
/// Update the status of an attendee
pub fn update_status(&mut self, status: AttendeeStatus) {
self.status = status;
}
}
/// Meeting represents a board meeting of a company or other meeting
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Meeting {
pub id: u32,
pub company_id: u32,
pub title: String,
pub date: DateTime<Utc>,
pub location: String,
pub description: String,
pub status: MeetingStatus,
pub minutes: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub attendees: Vec<Attendee>,
}
// Removed old Model trait implementation
impl Meeting {
/// Create a new meeting with default values
pub fn new(
id: u32,
company_id: u32,
title: String,
date: DateTime<Utc>,
location: String,
description: String,
) -> Self {
let now = Utc::now();
Self {
id,
company_id,
title,
date,
location,
description,
status: MeetingStatus::Scheduled,
minutes: String::new(),
created_at: now,
updated_at: now,
attendees: Vec::new(),
}
}
/// Add an attendee to the meeting
pub fn add_attendee(&mut self, attendee: Attendee) {
// Make sure the attendee's meeting_id matches this meeting
assert_eq!(self.id, attendee.meeting_id, "Attendee meeting_id must match meeting id");
// Check if the attendee already exists
if !self.attendees.iter().any(|a| a.id == attendee.id) {
self.attendees.push(attendee);
self.updated_at = Utc::now();
}
}
/// Update the status of the meeting
pub fn update_status(&mut self, status: MeetingStatus) {
self.status = status;
self.updated_at = Utc::now();
}
/// Update the meeting minutes
pub fn update_minutes(&mut self, minutes: String) {
self.minutes = minutes;
self.updated_at = Utc::now();
}
/// Find an attendee by user ID
pub fn find_attendee_by_user_id(&self, user_id: u32) -> Option<&Attendee> {
self.attendees.iter().find(|a| a.user_id == user_id)
}
/// Find an attendee by user ID (mutable version)
pub fn find_attendee_by_user_id_mut(&mut self, user_id: u32) -> Option<&mut Attendee> {
self.attendees.iter_mut().find(|a| a.user_id == user_id)
}
/// Get all confirmed attendees
pub fn confirmed_attendees(&self) -> Vec<&Attendee> {
self.attendees
.iter()
.filter(|a| a.status == AttendeeStatus::Confirmed)
.collect()
}
/// Link this meeting to a Calendar Event in the mcc module
pub fn link_to_event(&mut self, _event_id: u32) -> DbResult<()> {
// Implementation would involve updating a mapping in a separate database
// For now, we'll just update the timestamp to indicate the change
self.updated_at = Utc::now();
Ok(())
}
/// Get all resolutions discussed in this meeting
pub fn get_resolutions(&self, db: &DB) -> DbResult<Vec<super::Resolution>> {
let all_resolutions = db.list::<super::Resolution>()?;
let meeting_resolutions = all_resolutions
.into_iter()
.filter(|resolution| resolution.meeting_id == Some(self.id))
.collect();
Ok(meeting_resolutions)
}
}
impl Storable for Meeting{}
// Implement Model trait
impl Model for Meeting {
fn get_id(&self) -> u32 {
self.id
}
fn db_prefix() -> &'static str {
"meeting"
}
}