From fb551ad4aef6b4f76b3601dfca4425ac65600ea1 Mon Sep 17 00:00:00 2001 From: singhpranjali Date: Fri, 26 Aug 2022 20:00:44 +0200 Subject: [PATCH] correct response models --- marketplace/app/v0/object_storage.py | 86 ++++++++++++++++------------ 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/marketplace/app/v0/object_storage.py b/marketplace/app/v0/object_storage.py index 7973e7c..d8b32ce 100644 --- a/marketplace/app/v0/object_storage.py +++ b/marketplace/app/v0/object_storage.py @@ -1,8 +1,7 @@ import json -from typing import Dict, Union import marketplace_standard_app_api.models.object_storage as object_storage -from fastapi import UploadFile +from fastapi import Response, UploadFile from ..utils import check_capability_availability from .base import _MarketPlaceAppBase @@ -44,12 +43,14 @@ def create_or_update_collection( self, metadata: dict = None, collection_name: object_storage.CollectionName = None, - ): - return self._client.put( - self._proxy_path("createOrUpdateCollection"), - params={"collection_name": collection_name} if collection_name else {}, - headers=_encode_metadata(metadata), - ).json() + ) -> Response: + return Response( + self._client.put( + self._proxy_path("createOrUpdateCollection"), + params={"collection_name": collection_name} if collection_name else {}, + headers=_encode_metadata(metadata), + ).json() + ) @check_capability_availability def delete_collection(self, collection_name: object_storage.CollectionName): @@ -61,24 +62,26 @@ def delete_collection(self, collection_name: object_storage.CollectionName): @check_capability_availability def get_collection_metadata( self, collection_name: object_storage.CollectionName - ) -> Union[Dict, str]: + ) -> Response: response_headers: dict = self._client.head( self._proxy_path("getCollectionMetadata"), params={"collection_name": collection_name}, ).headers - return json.dumps(_decode_metadata(headers=response_headers)) + return Response(json.dumps(_decode_metadata(headers=response_headers))) @check_capability_availability def create_collection( self, collection_name: object_storage.CollectionName = None, metadata: dict = None, - ): - return self._client.put( - self._proxy_path("createCollection"), - params={"collection_name": collection_name} if collection_name else {}, - headers=_encode_metadata(metadata), - ).json() + ) -> Response: + return Response( + self._client.put( + self._proxy_path("createCollection"), + params={"collection_name": collection_name} if collection_name else {}, + headers=_encode_metadata(metadata), + ).json() + ) @check_capability_availability def create_dataset( @@ -106,26 +109,33 @@ def create_dataset_metadata( collection_name: object_storage.CollectionName, dataset_name: object_storage.DatasetName = None, metadata: dict = None, - ): + ) -> Response: params = {"collection_name": collection_name} if dataset_name: params.update({"dataset_name": dataset_name}) - return self._client.post( - self._proxy_path("createDatasetMetadata"), - params=params, - headers=_encode_metadata(metadata), - ).json() + return Response( + self._client.post( + self._proxy_path("createDatasetMetadata"), + params=params, + headers=_encode_metadata(metadata), + ).json() + ) @check_capability_availability def get_dataset( self, collection_name: object_storage.CollectionName, dataset_name: object_storage.DatasetName, - ) -> Union[Dict, str]: - return self._client.get( - self._proxy_path("getDataset"), - params={"collection_name": collection_name, "dataset_name": dataset_name}, - ).json() + ) -> Response: + return Response( + self._client.get( + self._proxy_path("getDataset"), + params={ + "collection_name": collection_name, + "dataset_name": dataset_name, + }, + ).json() + ) def create_or_replace_dataset( self, @@ -152,12 +162,17 @@ def create_or_replace_dataset_metadata( collection_name: object_storage.CollectionName, dataset_name: object_storage.DatasetName, metadata: dict = None, - ): - return self._client.put( - self._proxy_path("createOrReplaceDatasetMetadata"), - params={"collection_name": collection_name, "dataset_name": dataset_name}, - headers=_encode_metadata(metadata), - ).json() + ) -> Response: + return Response( + self._client.put( + self._proxy_path("createOrReplaceDatasetMetadata"), + params={ + "collection_name": collection_name, + "dataset_name": dataset_name, + }, + headers=_encode_metadata(metadata), + ).json() + ) @check_capability_availability def delete_dataset( @@ -170,18 +185,17 @@ def delete_dataset( params={"collection_name": collection_name, "dataset_name": dataset_name}, ) - # NOTE: change to GET for the meeting if proxy doesn't support HEAD requests @check_capability_availability def get_dataset_metadata( self, collection_name: object_storage.CollectionName, dataset_name: object_storage.DatasetName, - ) -> Union[Dict, str]: + ) -> Response: response_headers: dict = self._client.head( self._proxy_path("getDatasetMetadata"), params={"collection_name": collection_name, "dataset_name": dataset_name}, ).headers - return json.dumps(_decode_metadata(headers=response_headers)) + return Response(json.dumps(_decode_metadata(headers=response_headers))) @check_capability_availability def list_semantic_mappings(