Commit b38aa85f authored by Manuel Herold's avatar Manuel Herold

[businessLogic] finished enum-support

parent 6796bbfc
...@@ -509,6 +509,8 @@ paths: ...@@ -509,6 +509,8 @@ paths:
security: security:
- JwtRegular: [] - JwtRegular: []
operationId: "routes.enum.put_new" operationId: "routes.enum.put_new"
tags:
- "Enums"
summary: "Updates an existing Enum with a new value." summary: "Updates an existing Enum with a new value."
description: "Updates an existing Enum with a new value." description: "Updates an existing Enum with a new value."
parameters: parameters:
...@@ -527,11 +529,11 @@ paths: ...@@ -527,11 +529,11 @@ paths:
description: "Name of the Enum" description: "Name of the Enum"
required: true required: true
type: "string" type: "string"
- in: query - name: value
name: value in: query
schema:
type: string
description: Value of the Enum. description: Value of the Enum.
required: true
type: string
responses: responses:
'200': '200':
description: "Successful Request" description: "Successful Request"
......
...@@ -34,14 +34,11 @@ class EnumRepository(MongoRepositoryBase): ...@@ -34,14 +34,11 @@ class EnumRepository(MongoRepositoryBase):
return [Enum.from_serializable_dict(row) for row in list(result)] return [Enum.from_serializable_dict(row) for row in list(result)]
def one(self, name: str, use_case: str, table: str) -> Enum: def all_instances(self, name: str, use_case: str, table: str) -> Enum:
result = list(super().get_entries(self._enum_collection, selection={ result = list(super().get_entries(self._enum_collection, selection={
"name": name, "use_case": use_case, "table": table})) "name": name, "use_case": use_case, "table": table}))
if len(result) == 1: return [Enum.from_serializable_dict(row) for row in result]
return Enum.from_serializable_dict(result[0])
return None
def delete_all(self): def delete_all(self):
collection = self._database[self._enum_collection] collection = self._database[self._enum_collection]
......
...@@ -13,9 +13,11 @@ import connexion ...@@ -13,9 +13,11 @@ import connexion
from security import swagger_util from security import swagger_util
from env_info import is_running_locally, get_resources_path from env_info import is_running_locally, get_resources_path
from flask import request from flask import request
from flask_cors import CORS
from flask import redirect from flask import redirect
app = connexion.App(__name__, specification_dir='configs/') app = connexion.App(__name__, specification_dir='configs/')
CORS(app.app)
from db.entities.layer_adapter import LayerAdapter from db.entities.layer_adapter import LayerAdapter
......
...@@ -11,6 +11,7 @@ connexion==2.7.0 ...@@ -11,6 +11,7 @@ connexion==2.7.0
coverage==5.3.1 coverage==5.3.1
cryptography==3.1 cryptography==3.1
Flask==1.1.2 Flask==1.1.2
Flask-Cors==3.0.10
idna==2.10 idna==2.10
importlib-metadata==1.7.0 importlib-metadata==1.7.0
inflection==0.5.0 inflection==0.5.0
......
...@@ -48,10 +48,17 @@ def put_new(use_case: str, table: str, name: str, value: str): ...@@ -48,10 +48,17 @@ def put_new(use_case: str, table: str, name: str, value: str):
table - Required : unique identifier of the Table the Enum belongs to table - Required : unique identifier of the Table the Enum belongs to
name - Required : unique identifier for the Enum name - Required : unique identifier for the Enum
''' '''
existing_enum = enum_repository.one(name, use_case, table) existing_enums = enum_repository.all_instances(name, use_case, table)
enum_target = None
if existing_enum == None: found = False
return Response(status=404, response=f"Enum with name '{name}' does not exist!") for enum in existing_enums:
if enum.value == value:
enum_target = enum
break
if enum_target == None:
enum_target = Enum(use_case, table, name, value, len(existing_enums))
enum_repository.add(enum_target)
# todo return Response(status=200, response=json.dumps(enum_target.to_serializable_dict()))
return Response(status=200, response=json.dumps(existing_enum.to_serializable_dict())) \ No newline at end of file
\ No newline at end of file
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