From 850df534481057ec95a9b359023250e6c1ad2708 Mon Sep 17 00:00:00 2001 From: Dima Pristupa Date: Thu, 16 Jan 2025 21:02:28 +0200 Subject: [PATCH] DatasetEntryService: move list-* operations within an implementation --- .../src/services/dataset_entry_service.rs | 15 +-- .../src/dataset_entry_service_impl.rs | 96 +++++++++---------- 2 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/domain/datasets/domain/src/services/dataset_entry_service.rs b/src/domain/datasets/domain/src/services/dataset_entry_service.rs index f62a5d17f..9d50beebd 100644 --- a/src/domain/datasets/domain/src/services/dataset_entry_service.rs +++ b/src/domain/datasets/domain/src/services/dataset_entry_service.rs @@ -7,7 +7,6 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0. -use database_common::{EntityPageListing, PaginationOpts}; use internal_error::{ErrorIntoInternal, InternalError}; use opendatafabric as odf; use thiserror::Error; @@ -16,10 +15,9 @@ use crate::{DatasetEntry, DatasetEntryStream, GetDatasetEntryError}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// TODO: Private Datasets: tests #[async_trait::async_trait] pub trait DatasetEntryService: Sync + Send { - // TODO: Private Datasets: tests - // TODO: Private Datasets: extract to DatasetEntryRegistry? fn all_entries(&self) -> DatasetEntryStream; fn entries_owned_by(&self, owner_id: &odf::AccountID) -> DatasetEntryStream; @@ -28,17 +26,6 @@ pub trait DatasetEntryService: Sync + Send { &self, dataset_id: &odf::DatasetID, ) -> Result; - - async fn list_all_entries( - &self, - pagination: PaginationOpts, - ) -> Result, ListDatasetEntriesError>; - - async fn list_entries_owned_by( - &self, - owner_id: &odf::AccountID, - pagination: PaginationOpts, - ) -> Result, ListDatasetEntriesError>; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/domain/datasets/services/src/dataset_entry_service_impl.rs b/src/domain/datasets/services/src/dataset_entry_service_impl.rs index b17b57347..5a77191ee 100644 --- a/src/domain/datasets/services/src/dataset_entry_service_impl.rs +++ b/src/domain/datasets/services/src/dataset_entry_service_impl.rs @@ -277,6 +277,30 @@ impl DatasetEntryServiceImpl { } } + async fn list_all_entries( + &self, + pagination: PaginationOpts, + ) -> Result, ListDatasetEntriesError> { + use futures::TryStreamExt; + + let total_count = self + .dataset_entry_repo + .dataset_entries_count() + .await + .int_err()?; + let entries = self + .dataset_entry_repo + .get_dataset_entries(pagination) + .await + .try_collect() + .await?; + + Ok(EntityPageListing { + list: entries, + total_count, + }) + } + async fn list_all_dataset_handles( &self, pagination: PaginationOpts, @@ -292,6 +316,30 @@ impl DatasetEntryServiceImpl { }) } + async fn list_entries_owned_by( + &self, + owner_id: &odf::AccountID, + pagination: PaginationOpts, + ) -> Result, ListDatasetEntriesError> { + use futures::TryStreamExt; + + let total_count = self + .dataset_entry_repo + .dataset_entries_count_by_owner_id(owner_id) + .await?; + let entries = self + .dataset_entry_repo + .get_dataset_entries_by_owner_id(owner_id, pagination) + .await + .try_collect() + .await?; + + Ok(EntityPageListing { + list: entries, + total_count, + }) + } + async fn list_all_dataset_handles_by_owner_id( &self, owner_id: &odf::AccountID, @@ -345,54 +393,6 @@ impl DatasetEntryService for DatasetEntryServiceImpl { ) -> Result { self.dataset_entry_repo.get_dataset_entry(dataset_id).await } - - async fn list_all_entries( - &self, - pagination: PaginationOpts, - ) -> Result, ListDatasetEntriesError> { - use futures::TryStreamExt; - - let total_count = self - .dataset_entry_repo - .dataset_entries_count() - .await - .int_err()?; - let entries = self - .dataset_entry_repo - .get_dataset_entries(pagination) - .await - .try_collect() - .await?; - - Ok(EntityPageListing { - list: entries, - total_count, - }) - } - - async fn list_entries_owned_by( - &self, - owner_id: &odf::AccountID, - pagination: PaginationOpts, - ) -> Result, ListDatasetEntriesError> { - use futures::TryStreamExt; - - let total_count = self - .dataset_entry_repo - .dataset_entries_count_by_owner_id(owner_id) - .await?; - let entries = self - .dataset_entry_repo - .get_dataset_entries_by_owner_id(owner_id, pagination) - .await - .try_collect() - .await?; - - Ok(EntityPageListing { - list: entries, - total_count, - }) - } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////