Commit 36d573c1 authored by Manuel's avatar Manuel

businessLogic: added additional requests

parent 82e8dd19
......@@ -133,6 +133,153 @@ paths:
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-case/{use_case}/layers/use-case:
put:
security:
- JwtRegular: []
operationId: "routes.layer.update_use_case_for_all"
tags:
- "Layers"
summary: "Update the use-case of all layers belonging to the use-case in the query"
description: "Update the use-case of all layers belonging to the use-case in the query"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
use_case:
type: string
example: "air-bnb"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/mapping:
put:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/{name}/mapping:
delete:
security:
......
......@@ -118,6 +118,89 @@ paths:
description: "Layer does not exist"
'400':
description: "Field in request is missing or attribute does not exist in the Layer"
/use-case/{use_case}/layers/use-case:
put:
operationId: "routes.layer.update_use_case_for_all"
tags:
- "Layers"
summary: "Update the use-case of all layers belonging to the use-case in the query"
description: "Update the use-case of all layers belonging to the use-case in the query"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
use_case:
type: string
example: "air-bnb"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/mapping:
put:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/{name}/mapping:
delete:
operationId: "routes.layer.delete_mapping"
......@@ -189,16 +272,16 @@ paths:
'400':
description: "Field in request is missing"
/use-case/{use_case}/layers/{name}:
delete:
operationId: "routes.layer.delete_one"
get:
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Delete one LayerAdapter from the DB"
description: "Delete one LayerAdapter from the DB"
summary: "Retrieve one LayerAdapter from the DB"
description: "Retrieve one LayerAdapter from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
description: "Name of the layer"
required: true
type: "string"
- name: "use_case"
......@@ -211,16 +294,16 @@ paths:
description: "Successful Request"
'404':
description: "Layer does not exist"
get:
operationId: "routes.layer.one"
post:
operationId: "routes.layer.add"
tags:
- "Layers"
summary: "Retrieve one LayerAdapter from the DB"
description: "Retrieve one LayerAdapter from the DB"
summary: "Adds a new layer to the DB"
description: "Adds a new layer to the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer"
description: "Name of the new layer"
required: true
type: "string"
- name: "use_case"
......@@ -231,18 +314,18 @@ paths:
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
post:
operationId: "routes.layer.add"
'400':
description: "Layer already exists"
delete:
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Adds a new layer to the DB"
description: "Adds a new layer to the DB"
summary: "Delete one LayerAdapter from the DB"
description: "Delete one LayerAdapter from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the new layer"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
......@@ -253,8 +336,8 @@ paths:
responses:
'200':
description: "Successful Request"
'400':
description: "Layer already exists"
'404':
description: "Layer does not exist"
/layers:
post:
operationId: "routes.layer.add_complete"
......
......@@ -52,6 +52,10 @@ class Repository(MongoRepositoryBase):
def one_by_name_and_usecase(self, name : str, use_case: str) -> LayerAdapter:
return list(super().get_entries(self._adapter_collection, selection={"name": name, "use_case": use_case}))
def update_use_case(self, adapter : LayerAdapter, use_case: str):
collection = self._database[self._adapter_collection]
collection.update_one({"name":adapter.name, "use_case": use_case}, {"$set": adapter.to_serializable_dict()})
def update(self, adapter : LayerAdapter):
collection = self._database[self._adapter_collection]
collection.update_one({"name":adapter.name, "use_case": adapter.use_case}, {"$set": adapter.to_serializable_dict()})
......@@ -65,7 +69,7 @@ class Repository(MongoRepositoryBase):
return list(result)
def all_for_use_case(self, use_case: str) -> Dict:
def all_for_use_case(self, use_case: str) -> List[Dict]:
result = super().get_entries(self._adapter_collection, projection={'_id': False}, selection={"use_case": use_case})
return list(result)
\ No newline at end of file
......@@ -71,6 +71,26 @@ def one(name: str, use_case: str):
return Response(status=200, response=json.dumps(layer.to_serializable_dict()))
def add_mapping_for_all(use_case: str):
'''
add a new mapping to each layer of the use-case
@params:
use_case - Required : String-identifier for the use-case
'''
data = request.json
if "internal" not in data or "external" not in data:
return Response(status=400, response=f"Field missing! Fields required: (internal, external)")
layers = LayerAdapterService.all_for_use_case(use_case)
layers = [LayerAdapter.from_serializable_dict(d) for d in layers]
for layer in layers:
layer.add_mapping(data["internal"], data["external"])
LayerAdapterService.update(layer)
return Response(status=200)
def add_mapping(name: str, use_case: str):
'''
......@@ -95,6 +115,52 @@ def add_mapping(name: str, use_case: str):
return Response(status=200)
def update_use_case_for_all(use_case: str):
'''
update the use-case for each layer in the use-case
this changes the use-case of all layers, meaning the use-case used
for this request might not be usable after the request
@params:
use_case - Required : String-identifier for the use-case
'''
data = request.json
if "use_case" not in data:
return Response(status=400, response=f"Field missing! Fields required: (use_case)")
layers = LayerAdapterService.all_for_use_case(use_case)
layers = [LayerAdapter.from_serializable_dict(d) for d in layers]
for layer in layers:
layer.use_case = data["use_case"]
LayerAdapterService.update_use_case(layer, use_case)
return Response(status=200)
def delete_mapping_for_all(use_case: str):
'''
delete a mapping from each layer in the use-case
@params:
use_case - Required : String-identifier for the use-case
'''
data = request.json
if "internal" not in data:
return Response(status=400, response=f"Field missing! Fields required: (internal)")
layers = LayerAdapterService.all_for_use_case(use_case)
layers = [LayerAdapter.from_serializable_dict(d) for d in layers]
for layer in layers:
try:
layer.delete_mapping(data["internal"])
except ValueError:
continue
LayerAdapterService.update(layer)
return Response(status=200)
def delete_mapping(name: str, use_case: str):
'''
......
......@@ -16,6 +16,7 @@ class LayerAdapterService:
@staticmethod
def delete_all_use_cases():
LayerAdapterService._repository.delete_all_use_cases()
LayerAdapterService._repository.delete_all_layers()
@staticmethod
def delete_use_case(name:str):
......@@ -47,6 +48,17 @@ class LayerAdapterService:
'''
LayerAdapterService._repository.update(layer)
@staticmethod
def update_use_case(layer: LayerAdapter, use_case:str):
'''
Overwrite the stored instance with the given one which is
identified by the layer name
@params:
layer - Required : layer object holding the current data
'''
LayerAdapterService._repository.update_use_case(layer, use_case)
@staticmethod
def add(name: str, use_case: str):
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment