Skip to content

Commit

Permalink
DatasetEntryService: move list-* operations within an implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
s373r committed Jan 16, 2025
1 parent 0869efa commit 850df53
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 62 deletions.
15 changes: 1 addition & 14 deletions src/domain/datasets/domain/src/services/dataset_entry_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -28,17 +26,6 @@ pub trait DatasetEntryService: Sync + Send {
&self,
dataset_id: &odf::DatasetID,
) -> Result<DatasetEntry, GetDatasetEntryError>;

async fn list_all_entries(
&self,
pagination: PaginationOpts,
) -> Result<EntityPageListing<DatasetEntry>, ListDatasetEntriesError>;

async fn list_entries_owned_by(
&self,
owner_id: &odf::AccountID,
pagination: PaginationOpts,
) -> Result<EntityPageListing<DatasetEntry>, ListDatasetEntriesError>;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
96 changes: 48 additions & 48 deletions src/domain/datasets/services/src/dataset_entry_service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ impl DatasetEntryServiceImpl {
}
}

async fn list_all_entries(
&self,
pagination: PaginationOpts,
) -> Result<EntityPageListing<DatasetEntry>, 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,
Expand All @@ -292,6 +316,30 @@ impl DatasetEntryServiceImpl {
})
}

async fn list_entries_owned_by(
&self,
owner_id: &odf::AccountID,
pagination: PaginationOpts,
) -> Result<EntityPageListing<DatasetEntry>, 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,
Expand Down Expand Up @@ -345,54 +393,6 @@ impl DatasetEntryService for DatasetEntryServiceImpl {
) -> Result<DatasetEntry, GetDatasetEntryError> {
self.dataset_entry_repo.get_dataset_entry(dataset_id).await
}

async fn list_all_entries(
&self,
pagination: PaginationOpts,
) -> Result<EntityPageListing<DatasetEntry>, 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<EntityPageListing<DatasetEntry>, 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,
})
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 850df53

Please sign in to comment.