style: apply rustfmt to backend codebase
- Apply rustfmt to all Rust source files in backend/ - Fix trailing whitespace inconsistencies - Standardize formatting across handlers, models, and services - Improve code readability with consistent formatting These changes are purely stylistic and do not affect functionality. All CI checks now pass with proper formatting.
This commit is contained in:
parent
6b7e4d4016
commit
ee0feb77ef
41 changed files with 1266 additions and 819 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use mongodb::bson::DateTime;
|
||||
use mongodb::bson::{doc, oid::ObjectId};
|
||||
use mongodb::Collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use mongodb::bson::DateTime;
|
||||
|
||||
use super::permission::Permission;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ impl Share {
|
|||
active: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn is_expired(&self) -> bool {
|
||||
if let Some(expires) = self.expires_at {
|
||||
DateTime::now() > expires
|
||||
|
|
@ -50,11 +50,11 @@ impl Share {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn has_permission(&self, permission: &Permission) -> bool {
|
||||
self.permissions.contains(permission) || self.permissions.contains(&Permission::Admin)
|
||||
}
|
||||
|
||||
|
||||
pub fn revoke(&mut self) {
|
||||
self.active = false;
|
||||
}
|
||||
|
|
@ -69,19 +69,19 @@ impl ShareRepository {
|
|||
pub fn new(collection: Collection<Share>) -> Self {
|
||||
Self { collection }
|
||||
}
|
||||
|
||||
|
||||
pub async fn create(&self, share: &Share) -> mongodb::error::Result<Option<ObjectId>> {
|
||||
let result = self.collection.insert_one(share, None).await?;
|
||||
Ok(Some(result.inserted_id.as_object_id().unwrap()))
|
||||
}
|
||||
|
||||
|
||||
pub async fn find_by_id(&self, id: &ObjectId) -> mongodb::error::Result<Option<Share>> {
|
||||
self.collection.find_one(doc! { "_id": id }, None).await
|
||||
}
|
||||
|
||||
|
||||
pub async fn find_by_owner(&self, owner_id: &ObjectId) -> mongodb::error::Result<Vec<Share>> {
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
|
||||
self.collection
|
||||
.find(doc! { "owner_id": owner_id }, None)
|
||||
.await?
|
||||
|
|
@ -89,27 +89,37 @@ impl ShareRepository {
|
|||
.await
|
||||
.map_err(|e| mongodb::error::Error::from(e))
|
||||
}
|
||||
|
||||
pub async fn find_by_target(&self, target_user_id: &ObjectId) -> mongodb::error::Result<Vec<Share>> {
|
||||
|
||||
pub async fn find_by_target(
|
||||
&self,
|
||||
target_user_id: &ObjectId,
|
||||
) -> mongodb::error::Result<Vec<Share>> {
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
|
||||
self.collection
|
||||
.find(doc! { "target_user_id": target_user_id, "active": true }, None)
|
||||
.find(
|
||||
doc! { "target_user_id": target_user_id, "active": true },
|
||||
None,
|
||||
)
|
||||
.await?
|
||||
.try_collect()
|
||||
.await
|
||||
.map_err(|e| mongodb::error::Error::from(e))
|
||||
}
|
||||
|
||||
|
||||
pub async fn update(&self, share: &Share) -> mongodb::error::Result<()> {
|
||||
if let Some(id) = &share.id {
|
||||
self.collection.replace_one(doc! { "_id": id }, share, None).await?;
|
||||
self.collection
|
||||
.replace_one(doc! { "_id": id }, share, None)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub async fn delete(&self, share_id: &ObjectId) -> mongodb::error::Result<()> {
|
||||
self.collection.delete_one(doc! { "_id": share_id }, None).await?;
|
||||
self.collection
|
||||
.delete_one(doc! { "_id": share_id }, None)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue