feat: define device sync abstraction API

main
Jef Roosens 2025-03-16 15:30:21 +01:00
parent 0849c88796
commit 320a46c0f3
No known key found for this signature in database
GPG Key ID: 21FD3D77D56BAF49
3 changed files with 84 additions and 3 deletions

View File

@ -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<i64, gpodder::AuthErr> {
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<Utc>,
) -> Result<(), gpodder::AuthErr> {
todo!()
}
fn devices_by_sync_group(
&self,
user: &gpodder::User,
) -> Result<(Vec<gpodder::Device>, Vec<Vec<gpodder::Device>>), gpodder::AuthErr> {
todo!()
}
}

View File

@ -63,13 +63,44 @@ pub trait DeviceRepository {
fn devices_for_user(&self, user: &User) -> Result<Vec<Device>, 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<i64, AuthErr>;
/// 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<Utc>,
) -> 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<Device>, Vec<Vec<Device>>), 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<Vec<models::Subscription>, 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<Utc>,
) -> 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,

View File

@ -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<Vec<&str>>,
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<models::Device>, Vec<Vec<models::Device>>), AuthErr> {
self.store.devices_by_sync_group(user)
}
pub fn subscriptions_for_device(
&self,
user: &models::User,