feat(domain): add ApiKeyService, EngagementRepository ports; extend UserReader with list_paginated + find_by_ids

This commit is contained in:
2026-05-16 10:59:32 +02:00
parent 8628acfb77
commit f4db518167

View File

@@ -1,9 +1,11 @@
use std::collections::HashMap;
use crate::{ use crate::{
errors::DomainError, errors::DomainError,
events::{DomainEvent, EventEnvelope}, events::{DomainEvent, EventEnvelope},
models::{ models::{
api_key::ApiKey, api_key::ApiKey,
feed::{FeedEntry, PageParams, Paginated, UserSummary}, feed::{EngagementStats, FeedEntry, PageParams, Paginated, UserSummary, ViewerContext},
notification::Notification, notification::Notification,
remote_actor::RemoteActor, remote_actor::RemoteActor,
social::{Block, Boost, Follow, FollowState, Like}, 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 find_by_email(&self, email: &Email) -> Result<Option<User>, DomainError>;
async fn list_with_stats(&self) -> Result<Vec<UserSummary>, DomainError>; async fn list_with_stats(&self) -> Result<Vec<UserSummary>, DomainError>;
async fn count(&self) -> Result<i64, 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] #[async_trait]
@@ -115,6 +119,15 @@ pub trait BoostRepository: Send + Sync {
async fn count_for_thought(&self, thought_id: &ThoughtId) -> Result<i64, DomainError>; 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] #[async_trait]
pub trait FollowRepository: Send + Sync { pub trait FollowRepository: Send + Sync {
async fn save(&self, follow: &Follow) -> Result<(), DomainError>; 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 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] #[async_trait]
pub trait TopFriendRepository: Send + Sync { pub trait TopFriendRepository: Send + Sync {
async fn set_top_friends( async fn set_top_friends(