use mongodb::{ bson::{doc, oid::ObjectId, DateTime}, Collection, }; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Profile { #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] pub id: Option, #[serde(rename = "profileId")] pub profile_id: String, #[serde(rename = "userId")] pub user_id: String, #[serde(rename = "familyId")] pub family_id: Option, #[serde(rename = "name")] pub name: String, #[serde(rename = "nameIv")] pub name_iv: String, #[serde(rename = "nameAuthTag")] pub name_auth_tag: String, #[serde(rename = "role")] pub role: String, #[serde(rename = "permissions")] pub permissions: Vec, #[serde(rename = "createdAt")] pub created_at: DateTime, #[serde(rename = "updatedAt")] pub updated_at: DateTime, } pub struct ProfileRepository { collection: Collection, } impl ProfileRepository { pub fn new(collection: Collection) -> Self { Self { collection } } pub async fn create(&self, profile: &Profile) -> mongodb::error::Result<()> { self.collection.insert_one(profile, None).await?; Ok(()) } pub async fn find_by_profile_id( &self, profile_id: &str, ) -> mongodb::error::Result> { self.collection .find_one(doc! { "profileId": profile_id }, None) .await } }