This commit is contained in:
2025-04-20 09:42:22 +02:00
parent 616d3247b6
commit ec6da0b4e0
9 changed files with 125 additions and 56 deletions

View File

@@ -40,8 +40,8 @@ impl Calendar {
}
/// Get all events associated with this calendar
pub fn get_events(&self, db: &SledDB<Event>) -> SledDBResult<Vec<Event>> {
let all_events = db.list()?;
pub fn get_events(&self, db: &DB) -> DbResult<Vec<Event>> {
let all_events = db.list::<Event>()?;
let calendar_events = all_events
.into_iter()
.filter(|event| event.calendar_id == self.id)

View File

@@ -109,7 +109,7 @@ impl Contact {
// Implement Storable trait (provides default dump/load)
impl Storable for Contact {}
// Implement SledModel trait
// Implement Model trait
impl Model for Contact {
fn get_id(&self) -> u32 {
self.id

View File

@@ -85,13 +85,13 @@ impl Event {
}
/// Get the calendar this event belongs to
pub fn get_calendar(&self, db: &SledDB<Calendar>) -> SledDBResult<Calendar> {
db.get(&self.calendar_id.to_string())
pub fn get_calendar(&self, db: &DB) -> DbResult<Calendar> {
db.get::<Calendar>(self.calendar_id)
}
/// Get contacts for all attendees of this event
pub fn get_attendee_contacts(&self, db: &SledDB<Contact>) -> SledDBResult<Vec<Contact>> {
let all_contacts = db.list()?;
pub fn get_attendee_contacts(&self, db: &DB) -> DbResult<Vec<Contact>> {
let all_contacts = db.list::<Contact>()?;
let attendee_contacts = all_contacts
.into_iter()
.filter(|contact| self.attendees.contains(&contact.email))
@@ -129,10 +129,10 @@ impl Event {
// Implement Storable trait (provides default dump/load)
impl Storable for Event {}
// Implement SledModel trait
impl SledModel for Event {
fn get_id(&self) -> String {
self.id.to_string()
// Implement Model trait
impl Model for Event {
fn get_id(&self) -> u32 {
self.id
}
fn db_prefix() -> &'static str {

View File

@@ -12,4 +12,4 @@ pub use contacts::Contact;
pub use message::{Message, MessageMeta, MessageStatus};
// Re-export database components from db module
pub use crate::db::{SledDB, SledDBError, SledDBResult, Storable, SledModel, DB};
pub use crate::db::{DB, DBBuilder, Model, Storable, DbError, DbResult};

View File

@@ -151,10 +151,10 @@ impl Email {
// Implement Storable trait (provides default dump/load)
impl Storable for Email {}
// Implement SledModel trait
impl SledModel for Email {
fn get_id(&self) -> String {
self.id.to_string()
// Implement Model trait
impl Model for Email {
fn get_id(&self) -> u32 {
self.id
}
fn db_prefix() -> &'static str {

View File

@@ -108,8 +108,8 @@ impl Message {
}
/// Get all messages in the same thread
pub fn get_thread_messages(&self, db: &SledDB<Message>) -> SledDBResult<Vec<Message>> {
let all_messages = db.list()?;
pub fn get_thread_messages(&self, db: &DB) -> DbResult<Vec<Message>> {
let all_messages = db.list::<Message>()?;
let thread_messages = all_messages
.into_iter()
.filter(|msg| msg.thread_id == self.thread_id)
@@ -122,10 +122,10 @@ impl Message {
// Implement Storable trait (provides default dump/load)
impl Storable for Message {}
// Implement SledModel trait
impl SledModel for Message {
fn get_id(&self) -> String {
self.id.to_string()
// Implement Model trait
impl Model for Message {
fn get_id(&self) -> u32 {
self.id
}
fn db_prefix() -> &'static str {