feat(application): federation management use cases
This commit is contained in:
106
crates/application/src/use_cases/federation_management.rs
Normal file
106
crates/application/src/use_cases/federation_management.rs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
use domain::{
|
||||||
|
errors::DomainError, models::remote_actor::RemoteActor, ports::FederationActionPort,
|
||||||
|
value_objects::UserId,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn list_pending_requests(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> Result<Vec<RemoteActor>, DomainError> {
|
||||||
|
federation.get_pending_followers(user_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn accept_follow_request(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
actor_url: &str,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
federation.accept_follow_request(user_id, actor_url).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn reject_follow_request(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
actor_url: &str,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
federation.reject_follow_request(user_id, actor_url).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn list_remote_followers(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> Result<Vec<RemoteActor>, DomainError> {
|
||||||
|
federation.get_remote_followers(user_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove_remote_follower(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
actor_url: &str,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
federation.remove_remote_follower(user_id, actor_url).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn list_remote_following(
|
||||||
|
federation: &dyn FederationActionPort,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> Result<Vec<RemoteActor>, DomainError> {
|
||||||
|
federation.get_remote_following(user_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use domain::testing::TestStore;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_pending_returns_empty_by_default() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
let result = list_pending_requests(&store, &uid).await.unwrap();
|
||||||
|
assert!(result.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn accept_follow_request_returns_ok() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
accept_follow_request(&store, &uid, "https://mastodon.social/users/alice")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn reject_follow_request_returns_ok() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
reject_follow_request(&store, &uid, "https://mastodon.social/users/alice")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_remote_followers_returns_empty_by_default() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
let result = list_remote_followers(&store, &uid).await.unwrap();
|
||||||
|
assert!(result.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn remove_remote_follower_returns_ok() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
remove_remote_follower(&store, &uid, "https://mastodon.social/users/alice")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_remote_following_returns_empty_by_default() {
|
||||||
|
let store = TestStore::default();
|
||||||
|
let uid = UserId::new();
|
||||||
|
let result = list_remote_following(&store, &uid).await.unwrap();
|
||||||
|
assert!(result.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod api_keys;
|
pub mod api_keys;
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
pub mod federation_management;
|
||||||
pub mod feed;
|
pub mod feed;
|
||||||
pub mod notifications;
|
pub mod notifications;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
|
|||||||
Reference in New Issue
Block a user