use std::sync::Arc;
use async_trait::async_trait;
use fistinc_errors::ServiceResult;
use fistinc_paging::{Paging, QueryParams};
use uuid::Uuid;
use crate::domain::entity::PasswordChangeAction;
use crate::domain::PasswordHistoryRepository;
use crate::domain::services::PasswordHistoryService;
pub struct PasswordHistoryServiceImpl {
pub repository: Arc<dyn PasswordHistoryRepository>,
}
impl PasswordHistoryServiceImpl {
pub fn new(repository: Arc<dyn PasswordHistoryRepository>) -> Self {
PasswordHistoryServiceImpl { repository }
}
}
#[async_trait]
impl PasswordHistoryService for PasswordHistoryServiceImpl {
async fn get_all_user_password_changes(&self, user_id: Uuid) -> ServiceResult<Vec<PasswordChangeAction>> {
Ok(
self.repository
.find_all_user_password_changes(user_id).await?
)
}
async fn get_all_user_password_changes_paged(&self,
user_id: Uuid,
params: &dyn QueryParams,
) -> ServiceResult<Paging<PasswordChangeAction>> {
Ok(
self.repository
.find_all_user_password_changes_paged(user_id, params).await?
)
}
async fn save_password_change(&self, action: PasswordChangeAction) -> ServiceResult<PasswordChangeAction> {
self.repository
.save_password_change(&action).await?;
Ok(action)
}
}