feat(domain): add ApiKeyService, EngagementRepository ports; extend UserReader with list_paginated + find_by_ids
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
errors::DomainError,
|
||||
events::{DomainEvent, EventEnvelope},
|
||||
models::{
|
||||
api_key::ApiKey,
|
||||
feed::{FeedEntry, PageParams, Paginated, UserSummary},
|
||||
feed::{EngagementStats, FeedEntry, PageParams, Paginated, UserSummary, ViewerContext},
|
||||
notification::Notification,
|
||||
remote_actor::RemoteActor,
|
||||
social::{Block, Boost, Follow, FollowState, Like},
|
||||
@@ -56,6 +58,8 @@ pub trait UserReader: Send + Sync {
|
||||
async fn find_by_email(&self, email: &Email) -> Result<Option<User>, DomainError>;
|
||||
async fn list_with_stats(&self) -> Result<Vec<UserSummary>, DomainError>;
|
||||
async fn count(&self) -> Result<i64, DomainError>;
|
||||
async fn list_paginated(&self, page: PageParams) -> Result<Paginated<UserSummary>, DomainError>;
|
||||
async fn find_by_ids(&self, ids: &[UserId]) -> Result<HashMap<UserId, User>, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -115,6 +119,15 @@ pub trait BoostRepository: Send + Sync {
|
||||
async fn count_for_thought(&self, thought_id: &ThoughtId) -> Result<i64, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait EngagementRepository: Send + Sync {
|
||||
async fn get_for_thoughts(
|
||||
&self,
|
||||
thought_ids: &[ThoughtId],
|
||||
viewer_id: Option<&UserId>,
|
||||
) -> Result<HashMap<ThoughtId, (EngagementStats, Option<ViewerContext>)>, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait FollowRepository: Send + Sync {
|
||||
async fn save(&self, follow: &Follow) -> Result<(), DomainError>;
|
||||
@@ -180,6 +193,11 @@ pub trait ApiKeyRepository: Send + Sync {
|
||||
async fn delete(&self, id: &ApiKeyId, user_id: &UserId) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait ApiKeyService: Send + Sync {
|
||||
async fn validate_key(&self, raw_key: &str) -> Result<Option<UserId>, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait TopFriendRepository: Send + Sync {
|
||||
async fn set_top_friends(
|
||||
|
||||
Reference in New Issue
Block a user