From df6a884a50f862472a650f439adeb1419f5435ae Mon Sep 17 00:00:00 2001 From: Christian Boettcher <c.boettcher@fz-juelich.de> Date: Tue, 8 Jun 2021 11:51:18 +0200 Subject: [PATCH] tuples not supported by openapi as return type, needs to be something else for the /docs to work Switching back to dict for now, will look into it later --- apiserver/README.md | 7 ------- apiserver/main.py | 6 +++--- apiserver/storage/JsonFileStorageAdapter.py | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 apiserver/README.md diff --git a/apiserver/README.md b/apiserver/README.md deleted file mode 100644 index e720fc5..0000000 --- a/apiserver/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# TODO list - -- add testing stuff to readme -- merge and add CI Testing -- expand tests -- add authentication stuff - - find out how authentication is to be handled \ No newline at end of file diff --git a/apiserver/main.py b/apiserver/main.py index 2bb64cc..bf55e3f 100644 --- a/apiserver/main.py +++ b/apiserver/main.py @@ -4,7 +4,7 @@ Main module of data catalog api import logging from datetime import timedelta from enum import Enum -from typing import List, Tuple +from typing import Dict, List, Tuple from fastapi import FastAPI, HTTPException, Request, status from fastapi.param_functions import Depends @@ -84,7 +84,7 @@ async def get_specific_dataset(location_data_type: LocationDataType, dataset_id: """returns all information about a specific dataset, identified by id""" return adapter.get_details(location_data_type, dataset_id) -@app.post("/{location_data_type}", response_model=Tuple[str, LocationData]) +@app.post("/{location_data_type}", response_model=Dict[str, LocationData]) async def add_dataset(location_data_type: LocationDataType, dataset: LocationData, user: User = Depends(my_user)): @@ -92,7 +92,7 @@ async def add_dataset(location_data_type: LocationDataType, return adapter.add_new(location_data_type, dataset, user.username) -@app.put("/{location_data_type}/{dataset_id}", response_model=Tuple[str, LocationData]) +@app.put("/{location_data_type}/{dataset_id}", response_model=Dict[str, LocationData]) async def update_specific_dataset(location_data_type: LocationDataType, dataset_id: str, dataset: LocationData, user: User = Depends(my_user)): diff --git a/apiserver/storage/JsonFileStorageAdapter.py b/apiserver/storage/JsonFileStorageAdapter.py index bdae20d..8dd438b 100644 --- a/apiserver/storage/JsonFileStorageAdapter.py +++ b/apiserver/storage/JsonFileStorageAdapter.py @@ -73,7 +73,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter): to_store = StoredData(users=[user_name], actualData=data) with open(os.path.join(localpath, oid), 'w') as json_file: json.dump(to_store.dict(), json_file) - return (oid, data) + return {oid : data} def get_details(self, n_type: LocationDataType, oid: str): full_path = self.__get_object_path(value=n_type.value, oid=oid) @@ -89,7 +89,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter): with open(full_path, 'w') as f: json.dump(obj.dict(), f) - return (oid, data) + return {oid : data} def delete(self, n_type: LocationDataType, oid: str, usr: str): full_path = self.__get_object_path(value=n_type.value, oid=oid) -- GitLab