pub mod models; mod repository; pub use models::*; pub use repository::GpodderRepository; pub enum AuthErr { UnknownSession, UnknownUser, InvalidPassword, Other(Box), } pub trait Store: AuthStore + DeviceRepository + SubscriptionRepository {} impl Store for T where T: AuthStore + DeviceRepository + SubscriptionRepository {} pub trait AuthRepository { /// Validate the given session ID and return its user. fn validate_session(&self, session_id: i64) -> Result; /// Validate the credentials, returning the user if the credentials are correct. fn validate_credentials(&self, username: &str, password: &str) -> Result; /// Create a new session for the given user. fn create_session( &self, username: &str, password: &str, ) -> Result<(i64, models::User), AuthErr>; fn remove_session(&self, username: &str, session_id: i64) -> Result<(), AuthErr>; } pub trait AuthStore { /// Retrieve the session with the given session ID fn get_session(&self, session_id: i64) -> Result, AuthErr>; /// Retrieve the user with the given username fn get_user(&self, username: &str) -> Result, AuthErr>; /// Create a new session for a user with the given session ID fn insert_session(&self, session: &Session) -> Result<(), AuthErr>; /// Remove the session with the given session ID fn remove_session(&self, session_id: i64) -> Result<(), AuthErr>; } pub trait DeviceRepository { /// Return all devices associated with the user 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. fn update_device_info( &self, user: &User, device_id: &str, patch: DevicePatch, ) -> Result<(), AuthErr>; } pub trait SubscriptionRepository { /// Return the subscriptions for the given device fn subscriptions_for_device( &self, user: &User, device_id: &str, ) -> Result, AuthErr>; /// 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 fn set_subscriptions_for_device( &self, user: &User, device_id: &str, urls: Vec, time_changed: chrono::DateTime, ) -> Result<(), AuthErr>; /// Update the list of subscriptions for a device by adding and removing the given URLs fn update_subscriptions_for_device( &self, user: &User, device_id: &str, add: Vec, remove: Vec, time_changed: chrono::DateTime, ) -> Result<(), AuthErr>; /// Returns the changes in subscriptions since the given timestamp. fn subscription_updates_for_device( &self, user: &User, device_id: &str, since: chrono::DateTime, ) -> Result<(chrono::DateTime, Vec, Vec), AuthErr>; } pub trait EpisodeActionRepository { /// Insert the given episode actions into the datastore. fn add_episode_actions(&self, user: &User, actions: Vec) -> Result; /// Retrieve the list of episode actions for the given user. fn episode_actions_for_user( &self, user: &User, since: Option, podcast: Option, device: Option, aggregated: bool, ) -> Result<(i64, Vec), AuthErr>; }