diff --git a/ubisync/src/state/database/collections/apps.rs b/ubisync/src/state/database/collections/apps.rs index a90c0d2..5cb5b49 100644 --- a/ubisync/src/state/database/collections/apps.rs +++ b/ubisync/src/state/database/collections/apps.rs @@ -12,7 +12,7 @@ use crate::{ #[derive(Debug, Serialize, Deserialize, Collection, PartialEq, Clone)] #[collection(name = "apps", views = [])] -pub(super) struct DbApps { +pub(super) struct DbApp { #[natural_id] pub(super) id: AsKey, pub(super) last_access: DateTime, @@ -22,8 +22,8 @@ pub(super) struct DbApps { pub(super) default_pot: Option, } -impl From for App { - fn from(value: DbApps) -> Self { +impl From for App { + fn from(value: DbApp) -> Self { App { id: (*value.id).clone(), app_type: value.app_type, @@ -43,8 +43,8 @@ impl StateDB { description: String, app_type: String, ) -> anyhow::Result<()> { - DbApps::push( - DbApps { + DbApp::push( + DbApp { id: AsKey::new(id), last_access: Utc::now(), app_type, @@ -59,7 +59,7 @@ impl StateDB { } pub fn set_default_pot(&self, id: AppId, pot: PotId) -> anyhow::Result<()> { - DbApps::get(&AsKey::new(id), &self.db) + DbApp::get(&AsKey::new(id), &self.db) .unwrap() .unwrap() .modify(&self.db, |app| app.contents.default_pot = Some(pot.clone())) @@ -67,7 +67,7 @@ impl StateDB { } pub fn get_default_pot(&self, id: AppId) -> anyhow::Result> { - let pot_id = DbApps::get(&AsKey::new(id), &self.db)? + let pot_id = DbApp::get(&AsKey::new(id), &self.db)? .map(|app| app.contents.default_pot) .ok_or(Error::msg("App not found"))? .ok_or(Error::msg("Could not get default pot"))?; @@ -75,7 +75,7 @@ impl StateDB { } pub fn get_all_apps(&self) -> anyhow::Result> { - Ok(DbApps::all(&self.db) + Ok(DbApp::all(&self.db) .query()? .iter() .map(|app| app.contents.clone().into()) @@ -83,7 +83,7 @@ impl StateDB { } pub fn get_all_app_ids(&self) -> anyhow::Result> { - Ok(DbApps::all(&self.db) + Ok(DbApp::all(&self.db) .query()? .iter() .map(|app| (*app.contents.id).clone()) @@ -105,7 +105,7 @@ impl StateDB { } pub fn get_app(&self, id: AppId) -> anyhow::Result> { - DbApps::get(&AsKey::new(id), &self.db) + DbApp::get(&AsKey::new(id), &self.db) .map(|app_option| app_option.map(|app| app.contents.into())) .map_err(|e| anyhow!(e)) } diff --git a/ubisync/src/state/database/collections/mod.rs b/ubisync/src/state/database/collections/mod.rs index f7d6304..80ea251 100644 --- a/ubisync/src/state/database/collections/mod.rs +++ b/ubisync/src/state/database/collections/mod.rs @@ -1,10 +1,10 @@ use bonsaidb::core::schema::Schema; -use apps::DbApps; +use apps::DbApp; use elements::DbElement; -use peers::DbPeers; -use pot_memberships::DbPotMemberships; -use pots::DbPots; +use peers::DbPeer; +use pot_memberships::DbPotMembership; +use pots::DbPot; mod apps; mod elements; @@ -13,7 +13,7 @@ mod pot_memberships; mod pots; #[derive(Schema, Debug)] -#[schema(name = "ubisync", collections = [DbElement, DbPotMemberships, DbApps, DbPots, DbPeers])] +#[schema(name = "ubisync", collections = [DbElement, DbPotMembership, DbApp, DbPot, DbPeer])] pub struct UbisyncSchema; #[cfg(test)] diff --git a/ubisync/src/state/database/collections/peers.rs b/ubisync/src/state/database/collections/peers.rs index 5b21e38..c670ce0 100644 --- a/ubisync/src/state/database/collections/peers.rs +++ b/ubisync/src/state/database/collections/peers.rs @@ -11,22 +11,22 @@ use crate::state::database::{as_key::AsKey, StateDB}; #[derive(Debug, Serialize, Deserialize, Collection, PartialEq, Clone)] #[collection(name = "peers", views = [])] -pub(super) struct DbPeers { +pub(super) struct DbPeer { #[natural_id] pub(super) id: AsKey, pub(super) name: Option, } -impl From for Peer { - fn from(value: DbPeers) -> Self { +impl From for Peer { + fn from(value: DbPeer) -> Self { Peer::new((*value.id).clone(), value.name) } } impl StateDB { pub fn add_peer(&self, peer: Peer) -> anyhow::Result<()> { - DbPeers::push( - DbPeers { + DbPeer::push( + DbPeer { id: AsKey::new(peer.id()), name: peer.name(), }, @@ -37,20 +37,20 @@ impl StateDB { } pub fn get_peer(&self, id: PeerId) -> anyhow::Result> { - DbPeers::get(&AsKey::new(id), &self.db) + DbPeer::get(&AsKey::new(id), &self.db) .map(|doc| doc.map(|peer| Peer::new((*peer.contents.id).clone(), peer.contents.name))) .map_err(|e| anyhow!(e)) } pub fn get_all_peers(&self) -> anyhow::Result> { - DbPeers::all(&self.db) + DbPeer::all(&self.db) .query() .map(|peers| peers.iter().map(|p| p.contents.clone().into()).collect_vec()) .map_err(|e| anyhow!(e)) } pub fn set_peer_name(&self, id: PeerId, name: &Option) -> anyhow::Result<()> { - DbPeers::get(&AsKey::new(id), &self.db) + DbPeer::get(&AsKey::new(id), &self.db) .map_err(|e| anyhow!(e))? .ok_or(Error::msg("Peer not found"))? .modify(&self.db, |doc| doc.contents.name = name.clone()) diff --git a/ubisync/src/state/database/collections/pot_memberships.rs b/ubisync/src/state/database/collections/pot_memberships.rs index 085da84..bfa6d23 100644 --- a/ubisync/src/state/database/collections/pot_memberships.rs +++ b/ubisync/src/state/database/collections/pot_memberships.rs @@ -12,13 +12,13 @@ use crate::state::database::{as_key::AsKey, StateDB}; #[derive(Debug, Serialize, Deserialize, Collection, PartialEq, Clone)] #[collection(name = "pot_memberships", primary_key = u128, views = [DbPotMembershipsByPotId, DbPotMembershipsByAppId, DbPotMembershipsByBothIds])] -pub(super) struct DbPotMemberships { +pub(super) struct DbPotMembership { pub(super) pot_id: AsKey, pub(super) app_id: AsKey, } #[derive(Debug, Clone, View, ViewSchema)] -#[view(collection = DbPotMemberships, key = AsKey, value = Vec, name = "by-pot-id")] +#[view(collection = DbPotMembership, key = AsKey, value = Vec, name = "by-pot-id")] pub(super) struct DbPotMembershipsByPotId; impl MapReduce for DbPotMembershipsByPotId { @@ -26,7 +26,7 @@ impl MapReduce for DbPotMembershipsByPotId { &self, document: &'doc bonsaidb::core::document::BorrowedDocument<'_>, ) -> bonsaidb::core::schema::ViewMapResult<'doc, Self> { - let entry = DbPotMemberships::document_contents(document)?; + let entry = DbPotMembership::document_contents(document)?; document .header .emit_key_and_value(entry.pot_id, vec![(*entry.app_id).clone()]) @@ -48,7 +48,7 @@ impl MapReduce for DbPotMembershipsByPotId { } #[derive(Debug, Clone, View, ViewSchema)] -#[view(collection = DbPotMemberships, key = AsKey, value = Vec, name = "by-app-id")] +#[view(collection = DbPotMembership, key = AsKey, value = Vec, name = "by-app-id")] pub(super) struct DbPotMembershipsByAppId; impl MapReduce for DbPotMembershipsByAppId { @@ -56,7 +56,7 @@ impl MapReduce for DbPotMembershipsByAppId { &self, document: &'doc bonsaidb::core::document::BorrowedDocument<'_>, ) -> bonsaidb::core::schema::ViewMapResult<'doc, Self> { - let entry = DbPotMemberships::document_contents(document)?; + let entry = DbPotMembership::document_contents(document)?; document .header .emit_key_and_value(entry.app_id, vec![(*entry.pot_id).clone()]) @@ -78,7 +78,7 @@ impl MapReduce for DbPotMembershipsByAppId { } #[derive(Debug, Clone, View, ViewSchema)] -#[view(collection = DbPotMemberships, key = (AsKey, AsKey), value = DbPotMemberships, name = "by-both")] +#[view(collection = DbPotMembership, key = (AsKey, AsKey), value = DbPotMembership, name = "by-both")] pub(super) struct DbPotMembershipsByBothIds; impl MapReduce for DbPotMembershipsByBothIds { @@ -86,7 +86,7 @@ impl MapReduce for DbPotMembershipsByBothIds { &self, document: &'doc bonsaidb::core::document::BorrowedDocument<'_>, ) -> bonsaidb::core::schema::ViewMapResult<'doc, Self> { - let content = DbPotMemberships::document_contents(document)?; + let content = DbPotMembership::document_contents(document)?; document .header .emit_key_and_value((content.pot_id.clone(), content.app_id.clone()), content) @@ -104,8 +104,8 @@ impl StateDB { "A member app which does not exist was meant to be added to a pot", )) } else { - DbPotMemberships::push( - DbPotMemberships { + DbPotMembership::push( + DbPotMembership { pot_id: AsKey::new(pot), app_id: AsKey::new(app), }, diff --git a/ubisync/src/state/database/collections/pots.rs b/ubisync/src/state/database/collections/pots.rs index 215316f..7dfcfcd 100644 --- a/ubisync/src/state/database/collections/pots.rs +++ b/ubisync/src/state/database/collections/pots.rs @@ -7,22 +7,22 @@ use crate::state::database::{as_key::AsKey, StateDB}; #[derive(Debug, Serialize, Deserialize, Collection, PartialEq, Clone)] #[collection(name = "pots", views = [])] -pub(super) struct DbPots { +pub(super) struct DbPot { #[natural_id] pub(super) id: AsKey, pub(super) app_type: String, } -impl From for Pot { - fn from(value: DbPots) -> Self { +impl From for Pot { + fn from(value: DbPot) -> Self { Pot {id: (*value.id).clone(), app_type: value.app_type} } } impl StateDB { pub fn add_pot(&self, id: PotId, app_type: String) -> anyhow::Result<()> { - DbPots::push( - DbPots { + DbPot::push( + DbPot { id: AsKey::new(id), app_type, }, @@ -33,7 +33,7 @@ impl StateDB { } pub fn get_pot(&self, id: PotId) -> anyhow::Result> { - DbPots::get(&AsKey::new(id), &self.db) + DbPot::get(&AsKey::new(id), &self.db) .map(|pot_opt| pot_opt.map(|pot| pot.contents.into())) .map_err(|e| anyhow!(e)) }