Skip to content

Commit

Permalink
resturn json response when model not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
singhpranjali committed Sep 8, 2022
1 parent 6722ef2 commit 6de16e6
Showing 1 changed file with 41 additions and 50 deletions.
91 changes: 41 additions & 50 deletions marketplace/app/v0/object_storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from typing import Dict, Union

import marketplace_standard_app_api.models.object_storage as object_storage
from fastapi import Response, UploadFile
from fastapi import UploadFile

from ..utils import check_capability_availability
from .base import _MarketPlaceAppBase
Expand Down Expand Up @@ -43,14 +44,12 @@ def create_or_update_collection(
self,
metadata: dict = None,
collection_name: object_storage.CollectionName = None,
) -> Response:
return Response(
self._client.put(
self._proxy_path("createOrUpdateCollection"),
params={"collection_name": collection_name} if collection_name else {},
headers=_encode_metadata(metadata),
).json()
)
) -> Union[Dict, str]:
return 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):
Expand All @@ -62,26 +61,24 @@ def delete_collection(self, collection_name: object_storage.CollectionName):
@check_capability_availability
def get_collection_metadata(
self, collection_name: object_storage.CollectionName
) -> Response:
) -> Union[Dict, str]:
response_headers: dict = self._client.head(
self._proxy_path("getCollectionMetadata"),
params={"collection_name": collection_name},
).headers
return Response(json.dumps(_decode_metadata(headers=response_headers)))
return json.dumps(_decode_metadata(headers=response_headers))

@check_capability_availability
def create_collection(
self,
collection_name: object_storage.CollectionName = None,
metadata: dict = None,
) -> Response:
return Response(
self._client.put(
self._proxy_path("createCollection"),
params={"collection_name": collection_name} if collection_name else {},
headers=_encode_metadata(metadata),
).json()
)
) -> Union[Dict, str]:
return 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(
Expand Down Expand Up @@ -109,33 +106,29 @@ def create_dataset_metadata(
collection_name: object_storage.CollectionName,
dataset_name: object_storage.DatasetName = None,
metadata: dict = None,
) -> Response:
) -> Union[Dict, str]:
params = {"collection_name": collection_name}
if dataset_name:
params.update({"dataset_name": dataset_name})
return Response(
self._client.post(
self._proxy_path("createDatasetMetadata"),
params=params,
headers=_encode_metadata(metadata),
).json()
)
return 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,
) -> Response:
return Response(
self._client.get(
self._proxy_path("getDataset"),
params={
"collection_name": collection_name,
"dataset_name": dataset_name,
},
).json()
)
) -> Union[Dict, str]:
return self._client.get(
self._proxy_path("getDataset"),
params={
"collection_name": collection_name,
"dataset_name": dataset_name,
},
).json()

def create_or_replace_dataset(
self,
Expand All @@ -162,17 +155,15 @@ def create_or_replace_dataset_metadata(
collection_name: object_storage.CollectionName,
dataset_name: object_storage.DatasetName,
metadata: dict = None,
) -> Response:
return Response(
self._client.put(
self._proxy_path("createOrReplaceDatasetMetadata"),
params={
"collection_name": collection_name,
"dataset_name": dataset_name,
},
headers=_encode_metadata(metadata),
).json()
)
) -> Union[Dict, str]:
return 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(
Expand All @@ -190,12 +181,12 @@ def get_dataset_metadata(
self,
collection_name: object_storage.CollectionName,
dataset_name: object_storage.DatasetName,
) -> Response:
) -> Union[Dict, str]:
response_headers: dict = self._client.head(
self._proxy_path("getDatasetMetadata"),
params={"collection_name": collection_name, "dataset_name": dataset_name},
).headers
return Response(json.dumps(_decode_metadata(headers=response_headers)))
return json.dumps(_decode_metadata(headers=response_headers))

@check_capability_availability
def list_semantic_mappings(
Expand Down

0 comments on commit 6de16e6

Please sign in to comment.