Skip to content

Commit

Permalink
Refactor library content routes and controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
arash77 committed Sep 20, 2024
1 parent c5023cd commit 0f26838
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 96 deletions.
40 changes: 25 additions & 15 deletions lib/galaxy/schema/library_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ class LibraryContentsFileCreatePayload(LibraryContentsCreatePayload):
class LibraryContentsFolderCreatePayload(LibraryContentsCreatePayload):
name: Optional[str] = Field(
"",
title="(only if create_type is 'folder') name of the folder to create",
title="name of the folder to create",
)
description: Optional[str] = Field(
"",
title="(only if create_type is 'folder') description of the folder to create",
title="description of the folder to create",
)


Expand Down Expand Up @@ -211,15 +211,15 @@ class LibraryContentsShowDatasetResponse(LibraryContentsShowResponse):
folder_id: EncodedLibraryFolderDatabaseIdField
state: str
file_name: str
created_from_basename: str
created_from_basename: Optional[str]
uploaded_by: str
message: Optional[str]
date_uploaded: str
file_size: int
file_ext: str
data_type: str
misc_info: str
misc_blurb: str
misc_info: Optional[str]
misc_blurb: Optional[str]
peek: Optional[str]
uuid: str
metadata_dbkey: str
Expand All @@ -237,28 +237,34 @@ class LibraryContentsCreateFolderListResponse(RootModel):
root: List[LibraryContentsCreateFolderResponse]


class LibraryContentsCreateDatasetResponse(Model):
id: EncodedDatabaseIdField
class LibraryContentsCreateDatasetResponseBase(Model):
id: str # should change to EncodedDatabaseIdField latter
hda_ldda: str
model_class: str
name: str
deleted: bool
visible: bool
state: str
library_dataset_id: EncodedDatabaseIdField
library_dataset_id: str # should change to EncodedDatabaseIdField latter
file_size: int
file_name: str
update_time: str
file_ext: str
data_type: str
genome_build: str
misc_info: str
misc_blurb: str
created_from_basename: str
misc_info: Optional[str]
misc_blurb: Optional[str]
created_from_basename: Optional[str]
uuid: str
parent_library_id: EncodedDatabaseIdField
parent_library_id: str # should change to EncodedDatabaseIdField latter
metadata_dbkey: str
metadata_data_lines: int


class LibraryContentsCreateDatasetResponse(LibraryContentsCreateDatasetResponseBase):
metadata_data_lines: Optional[int]


class LibraryContentsCreateDatasetExtendedResponse(LibraryContentsCreateDatasetResponse):
metadata_comment_lines: Union[str, int]
metadata_columns: int
metadata_column_types: List[str]
Expand All @@ -267,8 +273,12 @@ class LibraryContentsCreateDatasetResponse(Model):


class LibraryContentsCreateDatasetListResponse(RootModel):
root: List[LibraryContentsCreateDatasetResponse]
root: List[LibraryContentsCreateDatasetResponseBase]


class LibraryContentsDeleteResponse(Model):
pass
id: EncodedDatabaseIdField
deleted: bool

class LibraryContentsPurgedResponse(LibraryContentsDeleteResponse):
purged: bool
17 changes: 14 additions & 3 deletions lib/galaxy/webapps/galaxy/api/library_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"""

import logging
from typing import Union
from typing import (
Optional,
Union,
)

from fastapi import Body

from galaxy.managers.context import (
ProvidesHistoryContext,
Expand All @@ -12,6 +17,7 @@
from galaxy.schema.fields import DecodedDatabaseIdField
from galaxy.schema.library_contents import (
LibraryContentsCollectionCreatePayload,
LibraryContentsCreateDatasetExtendedResponse,
LibraryContentsCreateDatasetListResponse,
LibraryContentsCreateDatasetResponse,
LibraryContentsCreateFolderListResponse,
Expand Down Expand Up @@ -72,12 +78,15 @@ def show(
def create(
self,
library_id: DecodedDatabaseIdField,
payload: Union[LibraryContentsFolderCreatePayload, LibraryContentsFileCreatePayload, LibraryContentsCollectionCreatePayload],
payload: Union[
LibraryContentsFolderCreatePayload, LibraryContentsFileCreatePayload, LibraryContentsCollectionCreatePayload
],
trans: ProvidesHistoryContext = DependsOnTrans,
) -> Union[
LibraryContentsCreateFolderListResponse,
LibraryContentsCreateDatasetResponse,
LibraryContentsCreateDatasetListResponse,
LibraryContentsCreateDatasetExtendedResponse,
]:
return self.service.create(trans, library_id, payload)

Expand All @@ -103,7 +112,9 @@ def delete(
self,
library_id: DecodedDatabaseIdField,
id: DecodedDatabaseIdField,
payload: LibraryContentsDeletePayload = LibraryContentsDeletePayload(),
payload: Optional[LibraryContentsDeletePayload] = Body(None),
trans: ProvidesHistoryContext = DependsOnTrans,
):
if payload is None:
payload = LibraryContentsDeletePayload()
return self.service.delete(trans, id, payload)
Loading

0 comments on commit 0f26838

Please sign in to comment.