Skip to content

Commit

Permalink
Updated implementation Docstrings/formatting TODO: Look over testing #35
Browse files Browse the repository at this point in the history
  • Loading branch information
asuresh-code committed Dec 9, 2024
1 parent e722ff2 commit 59eab0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions object_storage_api/repositories/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ def update(self, image_id: str, image: ImageIn, session: ClientSession = None) -
Updates an image from a MongoDB database.
:param image_id: The ID of the image to update.
:param image: The new image metadata.
:param image: The image containing the update data.
:param session: PyMongo ClientSession to use for database operations.
:return: List of images or an empty list if no images are retrieved.
:return: The updated image.
:raises InvalidObjectIdError: If the supplied `image_id` is invalid.
"""

logger.info("Updating image metadata with ID: %s", image_id)
Expand Down
9 changes: 5 additions & 4 deletions object_storage_api/routers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ def get_image(

@router.patch(
path="/{image_id}",
summary="Update image",
response_description="Updated Image",
summary="Update an image partially by ID",
response_description="Image updated successfully",
)
def partial_update_image(
image_id: Annotated[str, Path(description="ID of the image to update")],
image: ImagePatchMetadataSchema,
image_id: Annotated[str, Path(description="ID of the image to update")],
image_service: ImageServiceDep,
) -> ImageMetadataSchema:
# pylint: disable=missing-function-docstring
logger.info("Updating images")
logger.info("Partially updating image with ID: %s", image_id)
logger.debug("Image data: %s", image)

return image_service.update(image_id, image)
10 changes: 5 additions & 5 deletions object_storage_api/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ def list(self, entity_id: Optional[str] = None, primary: Optional[bool] = None)

def update(self, image_id: str, image: ImagePatchMetadataSchema) -> ImageMetadataSchema:
"""
Update an image based on its ID.
Update an image based by its ID.
:param image_id: The ID of the image to update.
:param image: The new update data for the image.
:return: List of images or an empty list if no images are retrieved.
:param image: The image containing the fields to be updated.
:return: The updated image.
"""
update_data = image.model_dump(exclude_unset=True)

stored_image = self._image_repository.get(image_id=image_id)

update_data = image.model_dump(exclude_unset=True)

updated_image = self._image_repository.update(
image_id=image_id, image=ImageIn(**{**stored_image.model_dump(), **update_data})
)
Expand Down

0 comments on commit 59eab0f

Please sign in to comment.