diff --git a/app/modules/dataset/repositories.py b/app/modules/dataset/repositories.py index 74983bbf6..433e31b47 100644 --- a/app/modules/dataset/repositories.py +++ b/app/modules/dataset/repositories.py @@ -82,6 +82,9 @@ def is_synchronized(self, dataset_id: int) -> bool: return True return False + ''' + Synchronised dataset + ''' def get_synchronized_datasets(self) -> List[DataSet]: return ( self.model.query.join(DSMetaData) @@ -90,18 +93,35 @@ def get_synchronized_datasets(self) -> List[DataSet]: .all() ) - def get_unsynchronized_datasets(self) -> List[DataSet]: + def get_synchronized_datasets_by_user(self, current_user_id: int) -> List[DataSet]: return ( self.model.query.join(DSMetaData) - .filter(DSMetaData.dataset_doi.is_(None)) + .filter(DataSet.user_id == current_user_id, DSMetaData.dataset_doi.isnot(None)) .order_by(self.model.created_at.desc()) .all() ) - def get_synchronized_datasets_by_user(self, current_user_id: int) -> List[DataSet]: + def get_synchronized_dataset_by_user(self, current_user_id: int, dataset_id: int) -> DataSet: return ( self.model.query.join(DSMetaData) - .filter(DataSet.user_id == current_user_id, DSMetaData.dataset_doi.isnot(None)) + .filter(DataSet.user_id == current_user_id, DataSet.id == dataset_id, DSMetaData.dataset_doi.isnot(None)) + .first() + ) + + def count_synchronized_datasets(self) -> int: + return ( + self.model.query.join(DSMetaData) + .filter(DSMetaData.dataset_doi.isnot(None)) + .count() + ) + + ''' + Unsynchronised dataset + ''' + def get_unsynchronized_datasets(self) -> List[DataSet]: + return ( + self.model.query.join(DSMetaData) + .filter(DSMetaData.dataset_doi.is_(None)) .order_by(self.model.created_at.desc()) .all() ) @@ -121,13 +141,6 @@ def get_unsynchronized_dataset_by_user(self, current_user_id: int, dataset_id: i .first() ) - def count_synchronized_datasets(self): - return ( - self.model.query.join(DSMetaData) - .filter(DSMetaData.dataset_doi.isnot(None)) - .count() - ) - def count_unsynchronized_datasets(self): return ( self.model.query.join(DSMetaData) @@ -135,6 +148,9 @@ def count_unsynchronized_datasets(self): .count() ) + ''' + Top X datasets... + ''' def latest_synchronized(self) -> List[DataSet]: return ( self.model.query.join(DSMetaData) diff --git a/app/modules/dataset/routes.py b/app/modules/dataset/routes.py index b01cda8a0..759059359 100644 --- a/app/modules/dataset/routes.py +++ b/app/modules/dataset/routes.py @@ -242,7 +242,7 @@ def subdomain_index(doi): def get_unsynchronized_dataset(dataset_id): # Get dataset - dataset = dataset_service.get_unsynchronized_dataset(current_user.id, dataset_id) + dataset = dataset_service.get_unsynchronized_dataset_by_user(current_user.id, dataset_id) if not dataset: abort(404) diff --git a/app/modules/dataset/services.py b/app/modules/dataset/services.py index dd6606bad..7a7278835 100644 --- a/app/modules/dataset/services.py +++ b/app/modules/dataset/services.py @@ -70,20 +70,39 @@ def move_feature_models(self, dataset: DataSet): def is_synchronized(self, dataset_id: int) -> bool: return self.repository.is_synchronized(dataset_id) + ''' + Synchronised dataset + ''' def get_synchronized_datasets(self) -> List[DataSet]: return self.repository.get_synchronized_datasets() - def get_unsynchronized_datasets(self) -> List[DataSet]: - return self.repository.get_unsynchronized_datasets() - def get_synchronized_datasets_by_user(self, current_user_id: int) -> List[DataSet]: return self.repository.get_synchronized_datasets_by_user(current_user_id) + def get_synchronized_dataset_by_user(self, current_user_id: int, dataset_id: int) -> DataSet: + return self.repository.get_synchronized_dataset_by_user(current_user_id, dataset_id) + + def count_synchronized_datasets(self) -> int: + return self.repository.count_synchronized_datasets() + + ''' + Unsynchronised dataset + ''' + def get_unsynchronized_datasets(self) -> List[DataSet]: + return self.repository.get_unsynchronized_datasets() + def get_unsynchronized_datasets_by_user(self, current_user_id: int) -> List[DataSet]: return self.repository.get_unsynchronized_datasets_by_user(current_user_id) - def get_unsynchronized_dataset(self, current_user_id: int, dataset_id: int) -> DataSet: - return self.repository.get_unsynchronized_dataset(current_user_id, dataset_id) + def get_unsynchronized_dataset_by_user(self, current_user_id: int, dataset_id: int) -> DataSet: + return self.repository.get_unsynchronized_dataset_by_user(current_user_id, dataset_id) + + def count_unsynchronized_datasets(self) -> int: + return self.repository.count_unsynchronized_datasets() + + ''' + Top X datasets... + ''' def latest_synchronized(self) -> List[DataSet]: return self.repository.latest_synchronized() @@ -91,9 +110,6 @@ def latest_synchronized(self) -> List[DataSet]: def get_top_5_datasets_by_feature_model_count(self) -> List[DataSet]: return self.repository.get_top_5_datasets_by_feature_model_count() - def count_synchronized_datasets(self) -> int: - return self.repository.count_synchronized_datasets() - def count_feature_models(self, dataset_id: int) -> int: dataset = self.repository.get_by_id(dataset_id) return dataset.feature_model_count