diff --git a/src/db/repository/device.rs b/src/db/repository/device.rs index 18a8516..2d02c1c 100644 --- a/src/db/repository/device.rs +++ b/src/db/repository/device.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; use diesel::prelude::*; use super::SqliteRepository; @@ -95,4 +96,35 @@ impl gpodder::DeviceRepository for SqliteRepository { Ok(()) } + + fn merge_sync_groups( + &self, + user: &gpodder::User, + device_ids: Vec<&str>, + ) -> Result { + todo!() + } + + fn remove_from_sync_group( + &self, + user: &gpodder::User, + device_ids: Vec<&str>, + ) -> Result<(), gpodder::AuthErr> { + todo!() + } + + fn synchronize_sync_group( + &self, + group_id: i64, + time_changed: DateTime, + ) -> Result<(), gpodder::AuthErr> { + todo!() + } + + fn devices_by_sync_group( + &self, + user: &gpodder::User, + ) -> Result<(Vec, Vec>), gpodder::AuthErr> { + todo!() + } } diff --git a/src/gpodder/mod.rs b/src/gpodder/mod.rs index fe904d4..7d26b84 100644 --- a/src/gpodder/mod.rs +++ b/src/gpodder/mod.rs @@ -63,13 +63,44 @@ pub trait DeviceRepository { fn devices_for_user(&self, user: &User) -> Result, AuthErr>; /// Update the information for the given device. If the device doesn't exist yet, it should be - /// created. + /// created without a sync group. fn update_device_info( &self, user: &User, device_id: &str, patch: DevicePatch, ) -> Result<(), AuthErr>; + + /// Add the devices to the same sync group by: + /// + /// * Merging the sync groups of all devices already in a sync group + /// * Adding all devices not yet in a sync group to the newly merged sync group + /// + /// # Returns + /// + /// ID of the final sync group + fn merge_sync_groups(&self, user: &User, device_ids: Vec<&str>) -> Result; + + /// Synchronize the sync group by adding or removing subscriptions to each device so that each + /// device's subscription state is the same + fn synchronize_sync_group( + &self, + group_id: i64, + time_changed: DateTime, + ) -> Result<(), AuthErr>; + + /// Remove the devices from their respective sync groups + fn remove_from_sync_group(&self, user: &User, device_ids: Vec<&str>) -> Result<(), AuthErr>; + + /// Return all devices for the user, grouped per sync group + /// + /// # Returns + /// + /// A tuple (unsynced devices, sync groups) + fn devices_by_sync_group( + &self, + user: &User, + ) -> Result<(Vec, Vec>), AuthErr>; } pub trait SubscriptionRepository { @@ -83,7 +114,8 @@ pub trait SubscriptionRepository { /// Return all subscriptions for a given user fn subscriptions_for_user(&self, user: &User) -> Result, AuthErr>; - /// Replace the list of subscriptions for a device with the given list + /// Replace the list of subscriptions for a device and all devices in its sync group with the + /// given list fn set_subscriptions_for_device( &self, user: &User, @@ -92,7 +124,8 @@ pub trait SubscriptionRepository { time_changed: DateTime, ) -> Result<(), AuthErr>; - /// Update the list of subscriptions for a device by adding and removing the given URLs + /// Update the list of subscriptions for a device and all devices in its sync group by adding + /// and removing the given URLs fn update_subscriptions_for_device( &self, user: &User, diff --git a/src/gpodder/repository.rs b/src/gpodder/repository.rs index e55d010..4cc17be 100644 --- a/src/gpodder/repository.rs +++ b/src/gpodder/repository.rs @@ -94,6 +94,22 @@ impl GpodderRepository { self.store.update_device_info(user, device_id, patch) } + pub fn update_device_sync_status( + &self, + user: &models::User, + sync: Vec>, + unsync: Vec<&str>, + ) -> Result<(), AuthErr> { + todo!("perform diff devices to sync and unsync") + } + + pub fn devices_by_sync_group( + &self, + user: &models::User, + ) -> Result<(Vec, Vec>), AuthErr> { + self.store.devices_by_sync_group(user) + } + pub fn subscriptions_for_device( &self, user: &models::User,