Skip to content

feat(favorite_external_directory): add external directories favorite#3239

Merged
mehdiwahada merged 75 commits into
devfrom
feat/add_external_directories_favorite
Jul 1, 2026
Merged

feat(favorite_external_directory): add external directories favorite#3239
mehdiwahada merged 75 commits into
devfrom
feat/add_external_directories_favorite

Conversation

@mehdiwahada

Copy link
Copy Markdown
Contributor

What does it do ? : Implements the addition of external directories as favorite

Why it has been done ? : The external directories don't have a stable id, so we need to add their path (workspace + current path) in the favorite handling API

How to test it ? : Try to add external directories with valid / invalid workspace or paths

Comment thread antarest/favorite/repository.py Outdated
)
result = self.session.execute(stmt)

return result.unique().scalar()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique seems useless here ?

@smailio smailio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice nice

I asked some questions and made some suggestions. Should be good after those are adressed.

Comment thread antarest/favorite/model.py Outdated
Comment on lines +91 to +99
class FavoriteExternalDirectory(Base):
__tablename__ = "favorite_external_directory"

path: Mapped[str] = mapped_column(String, primary_key=True)
workspace: Mapped[str] = mapped_column(String, primary_key=True)
user_id: Mapped[int] = mapped_column(Integer, primary_key=True)

def to_dto(self) -> "FavoriteExternalDirectoryDTO":
return FavoriteExternalDirectoryDTO(path=PosixPath(self.path), workspace=self.workspace)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add an alembic migration for this

study: Mapped["Study"] = relationship(Study)

def to_dto(self) -> FavoriteStudyDTO:
return FavoriteStudyDTO(study_id=self.study_id, study_name=self.study.name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hidden n+1 query btw

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be a good ticket for a refactoring, thanks for telling me

Comment thread antarest/favorite/service.py Outdated
Comment thread antarest/favorite/service.py Outdated
def __init__(
self, favorite_external_directory_repository: FavoriteExternalDirectoryRepository, workspace_config: Config
):
self._favorite_external_directory_repository = favorite_external_directory_repository

@smailio smailio Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why private member ? you didn't do this for sibling service

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an oversight on my part, I'll correct it. Thanks for the information.

Comment thread antarest/favorite/service.py Outdated
Comment thread antarest/favorite/repository.py Outdated
result = self.session.execute(stmt)
return list(result.scalars().all())

def get(self, workspace: str, path: str) -> FavoriteExternalDirectory | None:

@smailio smailio Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this get is only used in the delete service call. You can update the delete so that it checks the result.rowcount instead of doing a preventive check. You would save a db call most of the time a delete is called, and make the code base ligher.

Comment thread antarest/favorite/web.py
Comment on lines +77 to +81
def list_favorite_external_directories(
favorite_external_directory_service: FavoriteExternalDirectoryServiceDep,
) -> list[FavoriteExternalDirectoryDTO]:
logger.info("Listing favorite external directories for current user.")
return favorite_external_directory_service.list_favorites()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket mentionned an aggregate endpoint that would return all type of directories, maybe that's coming in a future PR ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it'll be in a coming PR, but I don't know when.

Comment thread antarest/favorite/model.py Fixed
Comment thread antarest/favorite/model.py Fixed
Comment thread antarest/favorite/model.py Fixed

@MartinBelthle MartinBelthle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 change to be done inside the alembic migration, after this we can merge :)

sa.Column('workspace', sa.String(length=255), nullable=False),
sa.Column('path', sa.String(length=255), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be mapped to identities.id instead of users.id, as you did in the model.py file

MartinBelthle
MartinBelthle previously approved these changes Jun 30, 2026
@mehdiwahada mehdiwahada requested a review from smailio June 30, 2026 07:55
Comment thread antarest/favorite/repository.py
Comment thread antarest/favorite/service.py
Comment thread antarest/favorite/model.py
Comment thread antarest/favorite/service.py Outdated
Comment thread antarest/favorite/service.py Outdated
Comment thread alembic/versions/80fdf2408ede_add_favorite_external_directory_table.py Outdated
@mehdiwahada mehdiwahada merged commit 26e74d5 into dev Jul 1, 2026
15 checks passed
@mehdiwahada mehdiwahada deleted the feat/add_external_directories_favorite branch July 1, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants