Skip to content
Snippets Groups Projects
Commit 58490616 authored by Christian Boettcher's avatar Christian Boettcher
Browse files

merge different locationtypes,

use the new interface to store data
(see #1)
parent f10efa7b
No related branches found
No related tags found
1 merge request!1apiserver based on fastAPI
......@@ -2,67 +2,57 @@ from typing import Optional
from typing import Dict
from fastapi import FastAPI
from fastapi import HTTPException
from pydantic import BaseModel
app = FastAPI()
from LocationStorage import LocationDataType
from LocationStorage import LocationData
from LocationStorage import AbstractLocationDataStorageAdapter
from JsonFileStorageAdapter import JsonFileStorageAdapter
from enum import Enum
class LocationData(BaseModel):
name: str
url: str
metadata: Optional[Dict[str, str]]
app = FastAPI(
title="API-Server for the Data Catalogue"
)
adapter: AbstractLocationDataStorageAdapter = JsonFileStorageAdapter()
#### A NOTE ON IDS
# the id of a dataset is not yet defined, it could be simply generated, it could be based on some hash of the metadata or simple be the name, which would then need to be enforced to be unique
# this might change some outputs of the GET functions that list reistered elements, but will very likely not change any part of the actual API
#### A NOTE ON LOCATION TYPES
# currently each type would need to be hardcoded, together will all api calls. It might be better to either allow any type of location Data (meaning the path fully defines it), or to make the type a forced metadata attributs.None
# this does not rule out the possibility to only enable specific location types, by comparing the requests to an enum of allowed types, which would be much more extensible
# list types of data locations, currently datasets (will be provided by the pillars) and targets (possible storage locations for worklfow results or similar)
@app.get("/")
def get_types():
return {"Datasets" : "/datasets", "Storage Targets" : "/targets"}
return [{element.value : "/" + element.value} for element in LocationDataType]
# list id and name of every registered dataset
@app.get("/datasets")
def list_datasets():
return {"A" : "JSON", "of" : "Pairs", "Dataset id": "Dataset Name"}
# list id and name of every registered dataset for the specified type
@app.get("/{location_data_type}")
def list_datasets(location_data_type : LocationDataType):
return adapter.getList(location_data_type)
# register a new dataset, the response will contain the new dataset and its id
@app.put("/datasets")
def add_dataset(dataset : LocationData):
# pretend to create the new dataset and store it
return "If this was working your dataset would now have been created with the id \"XXXXX\". The new dataset id would be provided in the response as a json (e.g. return \{dataset_id : dataset\})."
@app.put("/{location_data_type}")
def add_dataset(location_data_type : LocationDataType, dataset : LocationData):
return adapter.addNew(location_data_type, dataset)
# returns all information about a specific dataset, identified by id
@app.get("/datasets/{dataset_id}")
def get_specific_dataset(dataset_id: int):
return {"The JSON" : "of the dataset", "with the id" : dataset_id}
@app.get("/{location_data_type}/{dataset_id}")
def get_specific_dataset(location_data_type : LocationDataType, dataset_id: str):
try:
return adapter.getDetails(location_data_type, dataset_id)
except FileNotFoundError:
raise HTTPException(status_code=404, detail='The provided id does not exist for this datatype.')
# update the information about a specific dataset, identified by id
@app.put("/datasets/{dataset_id}")
def update_specific_dataset(dataset_id: int, dataset : LocationData):
return {"The Dataset" : "with the id", dataset_id : "has been upddated:", "name" : dataset.name, "url" : dataset.url, "metadata" : dataset.metadata}
# list id and name of every registered target
@app.get("/targets")
def list_targets():
return {"A" : "JSON", "of" : "Pairs", "target id": "target URL"}
# register a new target, the response will contain the new target and its id
@app.put("/targets")
def add_target(target : LocationData):
# pretend to create the new target and store it
return "If thsi was working your target would now have been created with the id \"XXXXX\". The new target would be provided in the response as a json (e.g. return \{target_id : target\})."
# returns all information about a specific target, identified by id
@app.get("/targets/{target_id}")
def get_specific_target(target_id: int):
return {"The JSON" : "of the target", "with the id" : target_id}
# update the information about a specific target, identified by id
@app.put("/targets/{target_id}")
def update_specific_target(target_id: int, target : LocationData):
return {"The target" : "with the id", target_id : "has been upddated:", "name" : target.name, "url" : target.url, "metadata" : target.metadata}
\ No newline at end of file
@app.put("/{location_data_type}/{dataset_id}")
def update_specific_dataset(location_data_type : LocationDataType, dataset_id: str, dataset : LocationData):
try:
return adapter.updateDetails(location_data_type, dataset_id, dataset)
except FileNotFoundError:
raise HTTPException(status_code=404, detail='The provided id does not exist for this datatype.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment